:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(flags): remove the flag-evaluations-hogql-table flag (#122238)
Phil Haack449ec3171369
diff --git a/docs/internal/clickhouse-deletion-coverage.md b/docs/internal/clickhouse-deletion-coverage.mdindex 58f40fe5abf7..97d9bfbe8546 100644--- a/docs/internal/clickhouse-deletion-coverage.md+++ b/docs/internal/clickhouse-deletion-coverage.md@@ -238,7 +238,7 @@ A flag row whose event the predicate does not name keeps its events copy and staA row with no events copy needs the predicate itself.An org on `flag_evaluations_mode` 2 stores its flag calls only in `flag_evaluations`, and a deletion that skipped the table can leave a flag row whose event is gone.`DeletionTarget.uncopied_rows_hogql_table` names the HogQL table that compiles the predicate for those rows, `posthog.flag_evaluations` here.-The compile adds that table even when the org flag hides it from queries.+The compile adds that table even when the org's mode hides it from queries.The queue fill reads the uuids of the rows with no copy in `sharded_events` that the compiled predicate matches, shard-locally and in 7-day windows, and queues them with the rest.A row read this way already existed when its uuid was queued, so the drain's `inserted_at` bound cannot skip it.The check for an events copy reads `sharded_events` only.diff --git a/frontend/src/scenes/feature-flags/flagEvaluationsTable.ts b/frontend/src/scenes/feature-flags/flagEvaluationsTable.tsindex e03008c9a620..6f18501de196 100644--- a/frontend/src/scenes/feature-flags/flagEvaluationsTable.ts+++ b/frontend/src/scenes/feature-flags/flagEvaluationsTable.ts@@ -5,8 +5,8 @@ import { FlagEvaluationsModeEnumApi } from '~/generated/core/api.schemas'import { CompareFilter } from '~/queries/schema/schema-general'import type { TeamPublicType, TeamType } from '~/types'-// Not a root table, so the `posthog.` prefix is part of the name. A team on the Events mode without-// the flag-evaluations-hogql-table flag has no such table. Queries on it fail to resolve for that team.+// Not a root table, so the `posthog.` prefix is part of the name. A team on the Events mode has no+// such table. Queries on it fail to resolve for that team.export const FLAG_EVALUATIONS_TABLE = 'posthog.flag_evaluations'export const FEATURE_FLAG_CALLED_EVENT = '$feature_flag_called'diff --git a/posthog/hogql/database/database.py b/posthog/hogql/database/database.pyindex 785840f89a6a..2121779e9c4f 100644--- a/posthog/hogql/database/database.py+++ b/posthog/hogql/database/database.py@@ -585,7 +585,7 @@ def _construct_database_root_node(*, include_posthog_tables: bool) -> TableNode:"logs_pattern_buckets": TableNode(name="logs_pattern_buckets", table=LogsPatternBucketsTable()),"ai_events": TableNode(name="ai_events", table=AiEventsTable()),# Pruned per org in _build_from_sources; see is_flag_evaluations_table_enabled.- # The flag check must stay out of this cached, process-global tree.+ # The organization mode check must stay out of this cached, process-global tree."flag_evaluations": TableNode(name="flag_evaluations", table=FlagEvaluationsTable()),"trace_spans": TableNode(name="trace_spans", table=TraceSpansTable()),"trace_attributes": TableNode(name="trace_attributes", table=TraceAttributesTable()),@@ -1792,8 +1792,8 @@ class Database(BaseModel):"""Build a query catalog, or a reduced catalog for schema serialization only.Query execution must omit schema_table_names because it can prune unrelated warehouse tables.- ``include_flag_evaluations_table`` overrides the organization flag that decides whether- ``posthog.flag_evaluations`` is in the catalog. None follows the flag.+ ``include_flag_evaluations_table`` overrides the organization's flag_evaluations mode, which decides+ whether ``posthog.flag_evaluations`` is in the catalog. None follows the mode."""build_started = time.perf_counter()@@ -1933,8 +1933,8 @@ class Database(BaseModel):direct_connection_metadata=None,user_access_control=None,denied_system_table_names=set(_scoped_system_tables()) | set(_system_table_required_features()),- # Resolving the org gate needs a feature-flag check, which is exactly the I/O this path- # exists to avoid, so the table is pruned here as the other gated tables are.+ # Resolving the org gate needs a Postgres read. This path exists to avoid that I/O,+ # so it prunes the table as it prunes the other gated tables.include_flag_evaluations_table=False,group_types=[],saved_queries=[],@@ -2361,8 +2361,8 @@ class Database(BaseModel):if posthog_node is not None:posthog_node.children.pop("billing_usage_records", None)- # Removing the node, rather than denying the table at query time, is what keeps an org that- # lacks the flag from learning it exists: serialize(), information_schema and get_table()+ # Removing the node, rather than denying the table at query time, keeps an org whose mode+ # hides the table from learning that it exists. serialize(), information_schema and get_table()# all read this tree. Must run before apply_schema_scope(), which snapshots the table names.# The "posthog" node is absent on a direct-connection catalog.if not sources.include_flag_evaluations_table:diff --git a/posthog/hogql/database/test/test_database.py b/posthog/hogql/database/test/test_database.pyindex f77df1356265..70fd037cfe55 100644--- a/posthog/hogql/database/test/test_database.py+++ b/posthog/hogql/database/test/test_database.py@@ -456,22 +456,24 @@ class TestDatabase(BaseTest, QueryMatchingTest):assert serialized_database.get(table_name) is not None@parameterized.expand([(True,), (False,)])- def test_flag_evaluations_visibility_follows_the_org_flag(self, flag_enabled: bool) -> None:+ def test_flag_evaluations_visibility_follows_the_table_gate(self, table_enabled: bool) -> None:with patch("products.feature_flags.backend.facade.flags.is_flag_evaluations_table_enabled",- return_value=flag_enabled,+ return_value=table_enabled,):database = Database.create_for(team=self.team)context = HogQLContext(team_id=self.team.pk, database=database)serialized = database.serialize(context, include_hidden_posthog_tables=True)- assert ("posthog.flag_evaluations" in database.get_posthog_table_names(include_hidden=True)) is flag_enabled- assert ("posthog.flag_evaluations" in serialized) is flag_enabled+ assert (+ "posthog.flag_evaluations" in database.get_posthog_table_names(include_hidden=True)+ ) is table_enabled+ assert ("posthog.flag_evaluations" in serialized) is table_enabled# The person traverser is the part that resolves through a virtual subtable rather than# straight to a column, so the query exercises that rather than a bare one.query = "SELECT flag_key, person.id, `$group_0` FROM posthog.flag_evaluations"- if flag_enabled:+ if table_enabled:execute_hogql_query(query, team=self.team, pretty=False)else:with pytest.raises(QueryError, match="Unknown table"):diff --git a/posthog/models/data_deletion_request.py b/posthog/models/data_deletion_request.pyindex ebf3415eb46a..e4cf46639379 100644--- a/posthog/models/data_deletion_request.py+++ b/posthog/models/data_deletion_request.py@@ -112,7 +112,7 @@ def compile_hogql_predicate(obj, use_new_events_schema: bool = False, hogql_tablraise ValidationError({"hogql_predicate": "team no longer exists; cannot validate the predicate."}) from excmodifiers = create_default_modifiers_for_team(team)modifiers.personsOnEventsMode = PersonsOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_ON_EVENTS- # The organization flag that hides posthog.flag_evaluations from queries does not apply here.+ # The organization mode that hides posthog.flag_evaluations from queries does not apply here.# The rows that table holds still have to be deletable.database = (None if on_events else Database.create_for(team=team, modifiers=modifiers, include_flag_evaluations_table=True)diff --git a/posthog/models/test/test_data_deletion_request.py b/posthog/models/test/test_data_deletion_request.pyindex 4636badb69f0..46e4a75e0e65 100644--- a/posthog/models/test/test_data_deletion_request.py+++ b/posthog/models/test/test_data_deletion_request.py@@ -361,7 +361,7 @@ def _flag_call_request(team: Team, hogql_predicate: str) -> DataDeletionRequest:)[email protected]("table_visible", [True, False], ids=["org_sees_the_table", "org_flag_hides_the_table"])[email protected]("table_visible", [True, False], ids=["org_sees_the_table", "org_mode_hides_the_table"])def test_compile_hogql_predicate_against_flag_evaluations_reads_its_own_columns(team, materialized_browser, table_visible):diff --git a/products/feature_flags/backend/facade/enums.py b/products/feature_flags/backend/facade/enums.pyindex 4f2ff63bad10..2e0582255383 100644--- a/products/feature_flags/backend/facade/enums.py+++ b/products/feature_flags/backend/facade/enums.py@@ -10,8 +10,7 @@ class FlagEvaluationsMode(LabeledIntEnum):allowlist includes."""- # Every reader of $feature_flag_called reads the events table. The flag_evaluations HogQL table stays- # hidden unless the flag-evaluations-hogql-table flag is on for the organization.+ # Every reader of $feature_flag_called reads the events table. The flag_evaluations HogQL table stays hidden.EVENTS = 0, "Events"# The Usage tab, the per-project counts on a flag's Projects tab, and events lists filtered to only# $feature_flag_called read flag_evaluations. Other readers, such as experiment exposures, still read events.diff --git a/products/feature_flags/backend/facade/flags.py b/products/feature_flags/backend/facade/flags.pyindex 2ab1c01f4103..1f2621fdcff9 100644--- a/products/feature_flags/backend/facade/flags.py+++ b/products/feature_flags/backend/facade/flags.py@@ -1,6 +1,6 @@-"""Feature-flag gates for this product, the read of an organization's flag_evaluations mode, and whether a team-has an active flag. The module stays light so core code can import it without pulling the facade's heavier logic-surface onto its import path.+"""The read of an organization's flag_evaluations mode, the gates built on it, and whether a team has an active+flag. The module stays light so core code can import it without pulling the facade's heavier logic surface onto+its import path."""from typing import TYPE_CHECKING@@ -9,7 +9,6 @@ from uuid import UUIDfrom django.conf import settingsfrom posthog.models.instance_setting import get_instance_setting-from posthog.ph_client import feature_enabled_or_falsefrom products.feature_flags.backend.facade.enums import FlagEvaluationsModefrom products.feature_flags.backend.models.feature_flag import FeatureFlag@@ -18,8 +17,6 @@ from products.feature_flags.backend.models.organization_feature_flags_config impif TYPE_CHECKING:from posthog.models.team import Team-FLAG_EVALUATIONS_HOGQL_TABLE_FEATURE_FLAG = "flag-evaluations-hogql-table"-def has_active_flags(team: "Team") -> bool:"""Whether the team has an active flag. Remote config sends this as `hasFeatureFlags`, and posthog-js requests@@ -65,30 +62,13 @@ def hides_flag_calls_from_query_builders(organization_id: UUID) -> bool:def is_flag_evaluations_table_enabled(team: "Team") -> bool:"""Gate every surface that exposes `posthog.flag_evaluations` through here.- Reads true when the flag_evaluations mode of the team's organization reads that table, or when the- flag-evaluations-hogql-table flag is on for the team's organization. A self-hosted production- instance has neither by default and reads false. Local dev and end-to-end tests are the- exception and read true.+ Reads true when the flag_evaluations mode of the team's organization reads that table. A self-hosted+ production instance reads false by default. Local dev and end-to-end tests are the exception and read true."""- # The flag is evaluated against PostHog's own analytics project, which a local or end-to-end- # environment has no membership in. Evaluating it there would hide the table from both, so- # return True to keep it visible in dev and E2E.+ # Local and E2E organizations start on EVENTS because FLAG_EVALUATIONS_NEW_ORG_MODE defaults to 0.+ # Returning True keeps the table queryable there without setting a mode first.if settings.DEBUG or settings.E2E_TESTING:return True- flag_enabled = feature_enabled_or_false(- FLAG_EVALUATIONS_HOGQL_TABLE_FEATURE_FLAG,- str(team.organization_id),- groups={"organization": str(team.organization_id)},- group_properties={"organization": {"id": str(team.organization_id)}},- # The HogQL database is built on the query hot path, and a local-evaluation miss otherwise- # blocks it on a synchronous request to /flags. Failing closed hides the table instead.- # This constrains how the flag may be configured: target organizations by the id sent- # above, because a condition on any property not sent here cannot evaluate locally and so- # reads false for everyone.- only_evaluate_locally=True,- send_feature_flag_events=False,- )- # The flag evaluates in memory, so it goes first and a flagged organization skips the query.- # The Usage tab reads flag_evaluations for any mode above EVENTS, and its query fails when the- # table is missing from the catalog, so the mode alone has to be enough.- return flag_enabled or get_organization_flag_evaluations_mode(team.organization_id) != FlagEvaluationsMode.EVENTS+ # The Usage tab reads flag_evaluations for any mode above EVENTS. Its query fails when the table+ # is missing from the catalog.+ return get_organization_flag_evaluations_mode(team.organization_id) != FlagEvaluationsMode.EVENTSdiff --git a/products/feature_flags/backend/test/test_organization_feature_flags_config.py b/products/feature_flags/backend/test/test_organization_feature_flags_config.pyindex 0055a133b7ed..c549e0e7f0bd 100644--- a/products/feature_flags/backend/test/test_organization_feature_flags_config.py+++ b/products/feature_flags/backend/test/test_organization_feature_flags_config.py@@ -1,5 +1,4 @@from posthog.test.base import BaseTest-from unittest.mock import patchfrom parameterized import parameterized@@ -45,29 +44,19 @@ class TestOrganizationFeatureFlagsConfig(BaseTest):class TestFlagEvaluationsTableGate(BaseTest):@parameterized.expand([- ("events_without_the_flag", FlagEvaluationsMode.EVENTS, False, False, False),- ("events_with_the_flag", FlagEvaluationsMode.EVENTS, True, False, True),- ("read_flag_evaluations_without_the_flag", FlagEvaluationsMode.READ_FLAG_EVALUATIONS, False, False, True),- (- "flag_evaluations_only_without_the_flag",- FlagEvaluationsMode.FLAG_EVALUATIONS_ONLY,- False,- False,- True,- ),- ("no_config_row_without_the_flag", None, False, False, False),+ ("events", FlagEvaluationsMode.EVENTS, False, False),+ ("read_flag_evaluations", FlagEvaluationsMode.READ_FLAG_EVALUATIONS, False, True),+ ("flag_evaluations_only", FlagEvaluationsMode.FLAG_EVALUATIONS_ONLY, False, True),+ ("no_config_row", None, False, False),("read_flag_evaluations_while_reads_are_forced_to_events",FlagEvaluationsMode.READ_FLAG_EVALUATIONS,- False,True,True,),])- def test_table_is_enabled_by_the_organization_mode_or_the_flag(- self, _name, mode, flag_enabled, reads_forced_to_events, expected- ):+ def test_table_is_enabled_by_the_organization_mode(self, _name, mode, reads_forced_to_events, expected):config = OrganizationFeatureFlagsConfig.objects.filter(organization=self.organization)if mode is None:config.delete()@@ -76,7 +65,6 @@ class TestFlagEvaluationsTableGate(BaseTest):with (self.settings(DEBUG=False, E2E_TESTING=False),- patch("products.feature_flags.backend.facade.flags.feature_enabled_or_false", return_value=flag_enabled),override_instance_config("FLAG_EVALUATIONS_READS_FORCE_EVENTS", reads_forced_to_events),):self.assertEqual(is_flag_evaluations_table_enabled(self.team), expected)