-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(insights): HogQL calculation of saved legacy insights v2 #21595
Conversation
bb87101
to
7a8db16
Compare
aa0de3e
to
f4db229
Compare
d404e98
to
92d44d7
Compare
3054a3e
to
230975e
Compare
package.json
Outdated
@@ -34,7 +34,8 @@ | |||
"build:esbuild": "node frontend/build.mjs", | |||
"schema:build": "pnpm run schema:build:json && pnpm run schema:build:python", | |||
"schema:build:json": "ts-node bin/build-schema.mjs && prettier --write frontend/src/queries/schema.json", | |||
"schema:build:python": "datamodel-codegen --class-name='SchemaRoot' --collapse-root-models --target-python-version 3.10 --disable-timestamp --use-one-literal-as-default --use-default --use-default-kwarg --use-subclass-enum --input frontend/src/queries/schema.json --input-file-type jsonschema --output posthog/schema.py --output-model-type pydantic_v2.BaseModel && ruff format posthog/schema.py", | |||
"schema:build:python": "datamodel-codegen --class-name='SchemaRoot' --collapse-root-models --target-python-version 3.10 --disable-timestamp --use-one-literal-as-default --use-default --use-default-kwarg --use-subclass-enum --input frontend/src/queries/schema.json --input-file-type jsonschema --output posthog/schema.py --output-model-type pydantic_v2.BaseModel && ruff format posthog/schema.py && pnpm schema:build:python:fix-up-enum", | |||
"schema:build:python:fix-up-enum": "sed -i '' -e 's/Optional\\[PropertyOperator\\] = \\(\"[A-Za-z_]*\"\\)/Optional[PropertyOperator] = PropertyOperator(\\1)/g' posthog/schema.py # THIS SED INVOCATION IS A MASSIVE HACK - remove when datamodel-codegen properly supports enums", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context: We need EventPropertyFilter.operator
to have a default value, to support the historic assumption that "exact" is the default operator. But that default value needs to be an enum member (PropertyOperator.exact
), which datamodel-codegen
doesn't support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move that into a shell file? (See build:json
above where I also moved to a file cause of more logic)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's definitely a good idea at this point! Done
Size Change: 0 B Total Size: 1.01 MB ℹ️ View Unchanged
|
ce321cd
to
79a61d3
Compare
This reverts commit a6314c6.
Wow, this was a pain to figure out, only was an issue in CI, because the trigger was `TestCohort::test_creating_update_and_calculating_with_new_cohort_query` running prior to `TestInsight:: test_insight_refreshing_query` – had to use trial and error.
Matters in CI.
281d302
to
4770169
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems alright in general. Some notes though.
Another thing I'm wondering for later:
If I go to an insight to view it, and it has been updated "1 day ago". I can click refresh there and it'll make just the request to /query
and then tell me "Computed a few seconds ago". But since we don't store this in the insight, upon refresh it'll be a day old again.
Not sure how to tie this in together... we probably cannot be sure the query is exactly the umodified insight and such 😩
package.json
Outdated
@@ -34,7 +34,8 @@ | |||
"build:esbuild": "node frontend/build.mjs", | |||
"schema:build": "pnpm run schema:build:json && pnpm run schema:build:python", | |||
"schema:build:json": "ts-node bin/build-schema.mjs && prettier --write frontend/src/queries/schema.json", | |||
"schema:build:python": "datamodel-codegen --class-name='SchemaRoot' --collapse-root-models --target-python-version 3.10 --disable-timestamp --use-one-literal-as-default --use-default --use-default-kwarg --use-subclass-enum --input frontend/src/queries/schema.json --input-file-type jsonschema --output posthog/schema.py --output-model-type pydantic_v2.BaseModel && ruff format posthog/schema.py", | |||
"schema:build:python": "datamodel-codegen --class-name='SchemaRoot' --collapse-root-models --target-python-version 3.10 --disable-timestamp --use-one-literal-as-default --use-default --use-default-kwarg --use-subclass-enum --input frontend/src/queries/schema.json --input-file-type jsonschema --output posthog/schema.py --output-model-type pydantic_v2.BaseModel && ruff format posthog/schema.py && pnpm schema:build:python:fix-up-enum", | |||
"schema:build:python:fix-up-enum": "sed -i '' -e 's/Optional\\[PropertyOperator\\] = \\(\"[A-Za-z_]*\"\\)/Optional[PropertyOperator] = PropertyOperator(\\1)/g' posthog/schema.py # THIS SED INVOCATION IS A MASSIVE HACK - remove when datamodel-codegen properly supports enums", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move that into a shell file? (See build:json
above where I also moved to a file cause of more logic)
], | ||
) | ||
self.assertEqual(response["last_refresh"], "2012-01-16T05:01:34Z") | ||
self.assertEqual(response["last_modified_at"], "2012-01-15T04:01:34Z") # did not change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, does that mean it didn't change from the non-dashboard one? Shouldn't it be different? Or it didn't change since creation? In the latter case we might adjust the case to make it clear we get a different not-change for dashboards 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is pretty valid, because the underlying definition of the insight hasn't changed. The dashboard config is just overlaid on top and kind of ephemeral. Unless I misunderstood?
@@ -313,8 +335,12 @@ def run(self, refresh_requested: Optional[bool] = None) -> CachedQueryResponse: | |||
return cached_response | |||
else: | |||
QUERY_CACHE_HIT_COUNTER.labels(team_id=self.team.pk, cache_hit="stale").inc() | |||
if execution_mode == ExecutionMode.CACHE_ONLY: | |||
return cached_response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to set is_cached = True
here as well? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yes, reworked and hopefully clarified this code overall
0fdf1e2
to
af5670b
Compare
Clarifies the `cached_response.is_cached = True` situation.
af5670b
to
e457fd4
Compare
📸 UI snapshots have been updated2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
Triggered by this commit. |
239b23b
to
0d86acb
Compare
This is exactly what should be addressed here. Just added a test to make sure the two endpoints indeed use the same cache, unlike previously. |
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
Changes
Revert of #21590, with
one changetwo changes added: