fix(cohorts): apply full HogQL global settings to recalculation query - #76424
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(cohorts): apply full HogQL global settings to recalculation query#76424posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
Cohort recalculation built its ClickHouse settings dict by hand, pulling only `max_ast_elements`/`max_expanded_ast_elements` out of `HogQLGlobalSettings` and dropping every other analyzer bugfix workaround (e.g. `optimize_rewrite_aggregate_function_with_if`, `optimize_min_inequality_conjunction_chain_length`). This left cohort recalculation queries exposed to distributed-analyzer header-mismatch bugs the rest of HogQL is protected from. Now spreads `get_default_hogql_global_settings(team_id=...).model_dump(exclude_none=True)` into the settings dict, layering the cohort-specific timeout/output overrides on top, so cohorts inherit current and future analyzer workarounds automatically. Generated-By: PostHog Code Task-Id: a88c449c-6624-405c-9a08-aff8bd51b20c
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CHQueryErrorNotFoundColumnInBlock: the ClickHouse initiator wanteduniq(__table1.$session_id), shards produced the backtick-quoted equivalent — same expression, different identifier quoting.HogQLGlobalSettings(posthog/hogql/constants.py)._recalculate_cohortpeople_for_team_hogqlbuilds SQL with the HogQL printer, then callssync_executewith a hand-rolled settings dict that only pullsmax_ast_elements/max_expanded_ast_elementsout ofHogQLGlobalSettings()— every other analyzer bugfix setting is silently dropped.Changes
_recalculate_cohortpeople_for_team_hogqlnow builds its settings dict by spreadingget_default_hogql_global_settings(team_id=...).model_dump(exclude_none=True), then layering the cohort-specific overrides (timeouts,optimize_on_insert, external group-by/sort ratios) on top.How did you test this code?
ruff check/ruff format --checkpass on the changed file.mypypasses on the changed file.products/cohorts/backend/models/test/test_util.pysuite or add a new regression test that asserts on the settings dict contents. The change is a mechanical widening of an existing dict spread (same pattern used elsewhere, e.g.lazy_computation_executor.py) with no behavior change beyond adding the previously-dropped settings.Automatic notifications
Docs update
🤖 Agent context
Autonomy: Fully autonomous
products/cohorts/backend/models/util.pyand the existing bugfix-workaround settings inposthog/hogql/constants.py.gh pr list/gh issue listsearches for related keywords and file paths turned up nothing addressing this specific gap.Created with PostHog Desktop from this inbox report.