Skip to content

: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.

chore(product-analytics): turn on the CI skip without new model crossings (#86647)

Julian Bez4f7ee44dabb8
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.yml
index 60d731e8f4dc..71660b2b91ad 100644
--- a/.depot/workflows/ci-backend.yml
+++ b/.depot/workflows/ci-backend.yml
@@ -855,7 +855,7 @@ jobs:
posthog/temporal/*|products/batch_exports/backend/tests/temporal/*|products/tasks/backend/temporal/*|products/signals/backend/emission/*)
temporal+=("$f")
;;
- posthog/clickhouse/*|posthog/queries/*|ee/clickhouse/*|products/product_analytics/backend/presentation/test/*|posthog/api/test/test_insight*|posthog/api/test/dashboards/test_dashboard.py)
+ posthog/clickhouse/*|posthog/queries/*|ee/clickhouse/*|products/product_analytics/backend/tests/api/*|posthog/api/test/test_insight*|posthog/api/test/dashboards/test_dashboard.py)
poe+=("$f")
core+=("$f")
;;
@@ -2229,7 +2229,7 @@ jobs:
if [[ "${{ matrix.compat }}" == "true" ]]; then
full_targets="$CLICKHOUSE_COMPAT_PYTEST_TARGETS"
elif [[ "${{ matrix.person-on-events }}" == "true" ]]; then
- full_targets="./posthog/clickhouse/ ./posthog/queries/ ./products/product_analytics/backend/presentation/test/ ./posthog/api/test/dashboards/test_dashboard.py ee/clickhouse/"
+ full_targets="./posthog/clickhouse/ ./posthog/queries/ ./products/product_analytics/backend/tests/api/ ./posthog/api/test/dashboards/test_dashboard.py ee/clickhouse/"
full_ignores+=(--ignore=posthog/hogql_queries --ignore=posthog/hogql)
fi
# shellcheck disable=SC2086
diff --git a/.github/scripts/trunk-impacted-targets.js b/.github/scripts/trunk-impacted-targets.js
index 3e964cbd6703..02061922c6e5 100644
--- a/.github/scripts/trunk-impacted-targets.js
+++ b/.github/scripts/trunk-impacted-targets.js
@@ -1339,10 +1339,15 @@ function addNodeLanes(targets) {
// package imports them. The python half cannot narrow below every python lane:
// the stubs are checked into posthog/, which is py:core, and py:core covers
// every product lane by construction.
+// stubDir names the checked-in stub directory when it differs from the tree
+// name; the consistency test reads it. ingestion's node stubs land in
+// nodejs/src/common/generated/ingestion-worker, not .../ingestion.
const PROTO_TREES = new Map([
['cymbal', { crates: ['cymbal-proto'], domains: [] }],
+ ['ingestion', { crates: ['ingestion-worker-proto'], domains: [NODE], stubDir: 'ingestion-worker' }],
['kafka_assigner', { crates: ['kafka-assigner-proto'], domains: [] }],
['personhog', { crates: ['personhog-proto'], domains: [PYTHON, NODE] }],
+ ['prometheus', { crates: ['prometheus-rw-proto'], domains: [] }],
])
// A file directly under proto/ is treated as impacting all trees, since it's not
diff --git a/.github/scripts/trunk-impacted-targets.test.js b/.github/scripts/trunk-impacted-targets.test.js
index 9cea5bfe7fd9..585b2e2895a9 100644
--- a/.github/scripts/trunk-impacted-targets.test.js
+++ b/.github/scripts/trunk-impacted-targets.test.js
@@ -109,16 +109,20 @@ const PROTO_CONTEXT = {
rustGraph: {
dependsOn: new Map([
['cymbal-proto', []],
+ ['ingestion-worker-proto', []],
['kafka-assigner-proto', []],
['personhog-proto', []],
['personhog-consumer', ['personhog-proto']],
+ ['prometheus-rw-proto', []],
['unrelated', []],
]),
byDir: [
{ dir: 'cymbal-proto', name: 'cymbal-proto' },
+ { dir: 'ingestion-worker-proto', name: 'ingestion-worker-proto' },
{ dir: 'kafka-assigner-proto', name: 'kafka-assigner-proto' },
{ dir: 'personhog-proto', name: 'personhog-proto' },
{ dir: 'personhog-consumer', name: 'personhog-consumer' },
+ { dir: 'prometheus-rw-proto', name: 'prometheus-rw-proto' },
{ dir: 'unrelated', name: 'unrelated' },
],
},
@@ -246,7 +250,9 @@ test('proto configuration at the root claims every tree', () => {
for (const file of [
'proto/personhog/types/v1/person.proto',
'proto/cymbal/resolution/v1/resolution.proto',
+ 'proto/ingestion/worker/v1/worker.proto',
'proto/kafka_assigner/v1/service.proto',
+ 'proto/prometheus/v1/remote_write.proto',
]) {
for (const target of computeTargets([file], PROTO_CONTEXT)) {
union.add(target)
@@ -337,9 +343,9 @@ test('every proto tree declaring a stub consumer has stubs there, and no other t
.readdirSync(path.join(REPO_ROOT, root), { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name)
- for (const [tree, { domains }] of PROTO_TREES) {
+ for (const [tree, { domains, stubDir }] of PROTO_TREES) {
assert.equal(
- generated.includes(tree),
+ generated.includes(stubDir || tree),
domains.includes(domain),
`proto/${tree} stubs in ${root} must match its declared ${domain} consumer`
)
diff --git a/.github/scripts/turbo-discover.js b/.github/scripts/turbo-discover.js
index 5d72834314b7..d9d7450b4804 100644
--- a/.github/scripts/turbo-discover.js
+++ b/.github/scripts/turbo-discover.js
@@ -539,7 +539,7 @@ const DJANGO_SEGMENTS = {
include: [
'posthog/clickhouse/',
'posthog/queries/',
- 'products/product_analytics/backend/presentation/test/',
+ 'products/product_analytics/backend/tests/api/',
'posthog/api/test/dashboards/test_dashboard.py',
'ee/clickhouse/',
],
diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml
index a0f31c0a6877..81a28ded22a6 100644
--- a/.github/workflows/ci-backend.yml
+++ b/.github/workflows/ci-backend.yml
@@ -786,7 +786,7 @@ jobs:
posthog/temporal/*|products/batch_exports/backend/tests/temporal/*|products/tasks/backend/temporal/*|products/signals/backend/emission/*)
temporal+=("$f")
;;
- posthog/clickhouse/*|posthog/queries/*|ee/clickhouse/*|products/product_analytics/backend/presentation/test/*|posthog/api/test/test_insight*|posthog/api/test/dashboards/test_dashboard.py)
+ posthog/clickhouse/*|posthog/queries/*|ee/clickhouse/*|products/product_analytics/backend/tests/api/*|posthog/api/test/test_insight*|posthog/api/test/dashboards/test_dashboard.py)
poe+=("$f")
core+=("$f")
;;
@@ -3263,7 +3263,7 @@ jobs:
if [[ "${{ matrix.compat }}" == "true" ]]; then
full_targets="$CLICKHOUSE_COMPAT_PYTEST_TARGETS"
elif [[ "${{ matrix.person-on-events }}" == "true" ]]; then
- full_targets="./posthog/clickhouse/ ./posthog/queries/ ./products/product_analytics/backend/presentation/test/ ./posthog/api/test/dashboards/test_dashboard.py ee/clickhouse/"
+ full_targets="./posthog/clickhouse/ ./posthog/queries/ ./products/product_analytics/backend/tests/api/ ./posthog/api/test/dashboards/test_dashboard.py ee/clickhouse/"
full_ignores+=(--ignore=posthog/hogql_queries --ignore=posthog/hogql)
fi
# shellcheck disable=SC2086
diff --git a/.test_durations b/.test_durations
index c9372919d77e..1f076b1fa160 100644
--- a/.test_durations
+++ b/.test_durations
@@ -86549,11 +86549,11 @@
"products/product_analytics/backend/models/test/test_insight_model.py::TestInsightModel::test_show_legend_property_0_query_with_show_legend_true": 0.012148786000125256,
"products/product_analytics/backend/models/test/test_insight_model.py::TestInsightModel::test_show_legend_property_1_legacy_filters_with_show_legend_true": 0.016213522000043668,
"products/product_analytics/backend/models/test/test_insight_model.py::TestInsightModel::test_show_legend_property_2_defaults_to_false": 0.016444272000057936,
- "products/product_analytics/backend/test/test_insight_activity_logging.py::TestChangesBetweenInsights::test_a_change_of_insight_dashboard_can_be_logged": 0.09721124600014264,
- "products/product_analytics/backend/test/test_insight_activity_logging.py::TestChangesBetweenInsights::test_insight_change_of_derived_name_can_be_logged": 0.03681291099996997,
- "products/product_analytics/backend/test/test_insight_activity_logging.py::TestChangesBetweenInsights::test_insight_change_of_description_can_be_logged": 0.028775361000157318,
- "products/product_analytics/backend/test/test_insight_activity_logging.py::TestChangesBetweenInsights::test_insight_change_of_name_can_be_logged": 0.025658442999997533,
- "products/product_analytics/backend/test/test_insight_activity_logging.py::TestChangesBetweenInsights::test_insight_change_of_tags_can_be_logged": 0.06642121900006259,
+ "products/product_analytics/backend/tests/test_insight_activity_logging.py::TestChangesBetweenInsights::test_a_change_of_insight_dashboard_can_be_logged": 0.09721124600014264,
+ "products/product_analytics/backend/tests/test_insight_activity_logging.py::TestChangesBetweenInsights::test_insight_change_of_derived_name_can_be_logged": 0.03681291099996997,
+ "products/product_analytics/backend/tests/test_insight_activity_logging.py::TestChangesBetweenInsights::test_insight_change_of_description_can_be_logged": 0.028775361000157318,
+ "products/product_analytics/backend/tests/test_insight_activity_logging.py::TestChangesBetweenInsights::test_insight_change_of_name_can_be_logged": 0.025658442999997533,
+ "products/product_analytics/backend/tests/test_insight_activity_logging.py::TestChangesBetweenInsights::test_insight_change_of_tags_can_be_logged": 0.06642121900006259,
"products/product_tours/backend/api/test/test_product_tour.py::TestProductTour::test_announcement_cannot_have_multiple_steps": 0.01,
"products/product_tours/backend/api/test/test_product_tour.py::TestProductTour::test_announcement_with_single_step_is_valid": 0.043149814999992486,
"products/product_tours/backend/api/test/test_product_tour.py::TestProductTour::test_can_create_product_tour": 0.02429103200006466,
diff --git a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
index 5bec7f662c4f..572d0425850e 100644
--- a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
+++ b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
@@ -2450,28 +2450,7 @@
# ---
# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.8
'''
- SELECT "posthog_dashboard"."id",
- "posthog_dashboard"."name",
- "posthog_dashboard"."description",
- "posthog_dashboard"."team_id",
- "posthog_dashboard"."pinned",
- "posthog_dashboard"."created_at",
- "posthog_dashboard"."created_by_id",
- "posthog_dashboard"."deleted",
- "posthog_dashboard"."last_accessed_at",
- "posthog_dashboard"."last_refresh",
- "posthog_dashboard"."filters",
- "posthog_dashboard"."variables",
- "posthog_dashboard"."breakdown_colors",
- "posthog_dashboard"."data_color_theme_id",
- "posthog_dashboard"."creation_mode",
- "posthog_dashboard"."restriction_level",
- "posthog_dashboard"."quick_filter_ids",
- "posthog_dashboard"."customization",
- "posthog_dashboard"."deprecated_tags",
- "posthog_dashboard"."tags",
- "posthog_dashboard"."share_token",
- "posthog_dashboard"."is_shared"
+ SELECT "posthog_dashboard"."id" AS "id"
FROM "posthog_dashboard"
INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id")
WHERE (NOT ("posthog_dashboard"."deleted")
@@ -2482,8 +2461,11 @@
LIMIT 1)
OR ("posthog_team"."parent_team_id" IS NULL
AND "posthog_dashboard"."team_id" = 99999))
- AND "posthog_dashboard"."id" = 99999)
- LIMIT 21
+ AND "posthog_dashboard"."id" IN (1,
+ 2,
+ 3,
+ 4,
+ 5 /* ... */))
'''
# ---
# name: TestDashboard.test_adding_insights_is_not_nplus1_for_gets.9
@@ -3693,28 +3675,7 @@
# ---
# name: TestDashboard.test_listing_dashboards_is_not_nplus1.6
'''
- SELECT "posthog_dashboard"."id",
- "posthog_dashboard"."name",
- "posthog_dashboard"."description",
- "posthog_dashboard"."team_id",
- "posthog_dashboard"."pinned",
- "posthog_dashboard"."created_at",
- "posthog_dashboard"."created_by_id",
- "posthog_dashboard"."deleted",
- "posthog_dashboard"."last_accessed_at",
- "posthog_dashboard"."last_refresh",
- "posthog_dashboard"."filters",
- "posthog_dashboard"."variables",
- "posthog_dashboard"."breakdown_colors",
- "posthog_dashboard"."data_color_theme_id",
- "posthog_dashboard"."creation_mode",
- "posthog_dashboard"."restriction_level",
- "posthog_dashboard"."quick_filter_ids",
- "posthog_dashboard"."customization",
- "posthog_dashboard"."deprecated_tags",
- "posthog_dashboard"."tags",
- "posthog_dashboard"."share_token",
- "posthog_dashboard"."is_shared"
+ SELECT "posthog_dashboard"."id" AS "id"
FROM "posthog_dashboard"
INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id")
WHERE (NOT ("posthog_dashboard"."deleted")
@@ -3725,8 +3686,11 @@
LIMIT 1)
OR ("posthog_team"."parent_team_id" IS NULL
AND "posthog_dashboard"."team_id" = 99999))
- AND "posthog_dashboard"."id" = 99999)
- LIMIT 21
+ AND "posthog_dashboard"."id" IN (1,
+ 2,
+ 3,
+ 4,
+ 5 /* ... */))
'''
# ---
# name: TestDashboard.test_listing_dashboards_is_not_nplus1.7
@@ -3994,108 +3958,6 @@
'''
# ---
# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.100
- '''
- SELECT "posthog_team"."id",
- "posthog_team"."uuid",
- "posthog_team"."organization_id",
- "posthog_team"."parent_team_id",
- "posthog_team"."project_id",
- "posthog_team"."api_token",
- "posthog_team"."app_urls",
- "posthog_team"."name",
- "posthog_team"."slack_incoming_webhook",
- "posthog_team"."created_at",
- "posthog_team"."updated_at",
- "posthog_team"."anonymize_ips",
- "posthog_team"."completed_snippet_onboarding",
- "posthog_team"."has_completed_onboarding_for",
- "posthog_team"."onboarding_tasks",
- "posthog_team"."ingested_event",
- "posthog_team"."ingested_production_event",
- "posthog_team"."ingested_production_event_last_checked_at",
- "posthog_team"."person_processing_opt_out",
- "posthog_team"."secret_api_token",
- "posthog_team"."secret_api_token_backup",
- "posthog_team"."session_recording_opt_in",
- "posthog_team"."session_recording_sample_rate",
- "posthog_team"."session_recording_minimum_duration_milliseconds",
- "posthog_team"."session_recording_linked_flag",
- "posthog_team"."session_recording_network_payload_capture_config",
- "posthog_team"."session_recording_masking_config",
- "posthog_team"."session_recording_url_trigger_config",
- "posthog_team"."session_recording_url_blocklist_config",
- "posthog_team"."session_recording_event_trigger_config",
- "posthog_team"."session_recording_trigger_match_type_config",
- "posthog_team"."session_recording_trigger_groups",
- "posthog_team"."session_replay_config",
- "posthog_team"."session_recording_retention_period",
- "posthog_team"."event_retention_months",
- "posthog_team"."conversations_enabled",
- "posthog_team"."conversations_settings",
- "posthog_team"."proactive_tasks_enabled",
- "posthog_team"."survey_config",
- "posthog_team"."surveys_opt_in",
- "posthog_team"."product_tours_opt_in",
- "posthog_team"."capture_console_log_opt_in",
- "posthog_team"."capture_performance_opt_in",
- "posthog_team"."capture_dead_clicks",
- "posthog_team"."autocapture_opt_out",
- "posthog_team"."autocapture_web_vitals_opt_in",
- "posthog_team"."autocapture_web_vitals_allowed_metrics",
- "posthog_team"."autocapture_exceptions_opt_in",
- "posthog_team"."autocapture_exceptions_errors_to_ignore",
- "posthog_team"."logs_settings",
- "posthog_team"."llm_gateway_enabled_at",
- "posthog_team"."llm_gateway_revoked_at",
- "posthog_team"."llm_gateway_overspend_allowance_usd",
- "posthog_team"."heatmaps_opt_in",
- "posthog_team"."receive_org_level_activity_logs",
- "posthog_team"."web_analytics_pre_aggregated_tables_enabled",
- "posthog_team"."web_analytics_pre_aggregated_tables_version",
- "posthog_team"."flags_persistence_default",
- "posthog_team"."feature_flag_confirmation_enabled",
- "posthog_team"."feature_flag_confirmation_message",
- "posthog_team"."default_evaluation_environments_enabled",
- "posthog_team"."require_evaluation_environment_tags",
- "posthog_team"."default_evaluation_contexts_enabled",
- "posthog_team"."require_evaluation_contexts",
- "posthog_team"."session_recording_version",
- "posthog_team"."signup_token",
- "posthog_team"."is_demo",
- "posthog_team"."access_control",
- "posthog_team"."week_start_day",
- "posthog_team"."inject_web_apps",
- "posthog_team"."test_account_filters",
- "posthog_team"."test_account_filters_default_checked",
- "posthog_team"."path_cleaning_filters",
- "posthog_team"."timezone",
- "posthog_team"."data_attributes",
- "posthog_team"."person_display_name_properties",
- "posthog_team"."live_events_columns",
- "posthog_team"."recording_domains",
- "posthog_team"."human_friendly_comparison_periods",
- "posthog_team"."cookieless_server_hash_mode",
- "posthog_team"."primary_dashboard_id",
- "posthog_team"."default_data_theme",
- "posthog_team"."extra_settings",
- "posthog_team"."modifiers",
- "posthog_team"."correlation_config",
- "posthog_team"."session_recording_retention_period_days",
- "posthog_team"."external_data_workspace_id",
- "posthog_team"."external_data_workspace_last_synced_at",
- "posthog_team"."api_query_rate_limit",
- "posthog_team"."drop_events_older_than",
- "posthog_team"."base_currency",
- "posthog_team"."experiment_recalculation_time",
- "posthog_team"."default_experiment_confidence_level",
- "posthog_team"."default_experiment_stats_method",
- "posthog_team"."business_model"
- FROM "posthog_team"
- WHERE "posthog_team"."id" = 99999
- LIMIT 21
- '''
-# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.101
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -4122,7 +3984,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.102
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.101
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -4149,7 +4011,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.103
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.102
'''
SELECT "posthog_insightvariable"."created_by_id",
"posthog_insightvariable"."created_at",
@@ -4168,7 +4030,7 @@
WHERE "posthog_insightvariable"."team_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.104
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.103
'''
SELECT "posthog_dashboardtile"."dashboard_id" AS "dashboard_id"
FROM "posthog_dashboardtile"
@@ -4179,7 +4041,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.105
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.104
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -4212,7 +4074,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.106
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.105
'''
SELECT "posthog_tag"."name" AS "tag__name"
FROM "posthog_taggeditem"
@@ -4220,7 +4082,7 @@
WHERE "posthog_taggeditem"."insight_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.107
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.106
'''
SELECT "posthog_user"."id",
"posthog_user"."password",
@@ -4266,7 +4128,7 @@
AND "posthog_user"."id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.108
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.107
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -4311,7 +4173,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.109
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.108
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -4452,19 +4314,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.11
- '''
- SELECT COUNT(*) AS "__count"
- FROM "posthog_dashboardtile"
- INNER JOIN "posthog_dashboard" ON ("posthog_dashboardtile"."dashboard_id" = "posthog_dashboard"."id")
- WHERE (NOT ("posthog_dashboardtile"."deleted"
- AND "posthog_dashboardtile"."deleted" IS NOT NULL)
- AND NOT ("posthog_dashboard"."deleted")
- AND "posthog_dashboardtile"."dashboard_id" = 99999
- AND NOT ("posthog_dashboardtile"."insight_id" IS NULL))
- '''
-# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.110
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.109
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -4518,7 +4368,19 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.111
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.11
+ '''
+ SELECT COUNT(*) AS "__count"
+ FROM "posthog_dashboardtile"
+ INNER JOIN "posthog_dashboard" ON ("posthog_dashboardtile"."dashboard_id" = "posthog_dashboard"."id")
+ WHERE (NOT ("posthog_dashboardtile"."deleted"
+ AND "posthog_dashboardtile"."deleted" IS NOT NULL)
+ AND NOT ("posthog_dashboard"."deleted")
+ AND "posthog_dashboardtile"."dashboard_id" = 99999
+ AND NOT ("posthog_dashboardtile"."insight_id" IS NULL))
+ '''
+# ---
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.110
'''
SELECT "ee_accesscontrol"."id",
"ee_accesscontrol"."team_id",
@@ -4543,7 +4405,7 @@
AND "ee_accesscontrol"."team_id" = 99999))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.112
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.111
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -4595,7 +4457,7 @@
WHERE "posthog_organizationmembership"."user_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.113
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.112
'''
SELECT "ee_accesscontrol"."team_id" AS "team_id",
"ee_accesscontrol"."resource_id" AS "resource_id",
@@ -4608,7 +4470,7 @@
AND "posthog_team"."organization_id" IN ('00000000-0000-0000-0000-000000000000'::uuid))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.114
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.113
'''
SELECT "ee_role"."organization_id" AS "role__organization_id",
"ee_rolemembership"."role_id" AS "role_id"
@@ -4617,30 +4479,9 @@
WHERE "ee_rolemembership"."user_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.115
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.114
'''
- SELECT "posthog_dashboard"."id",
- "posthog_dashboard"."name",
- "posthog_dashboard"."description",
- "posthog_dashboard"."team_id",
- "posthog_dashboard"."pinned",
- "posthog_dashboard"."created_at",
- "posthog_dashboard"."created_by_id",
- "posthog_dashboard"."deleted",
- "posthog_dashboard"."last_accessed_at",
- "posthog_dashboard"."last_refresh",
- "posthog_dashboard"."filters",
- "posthog_dashboard"."variables",
- "posthog_dashboard"."breakdown_colors",
- "posthog_dashboard"."data_color_theme_id",
- "posthog_dashboard"."creation_mode",
- "posthog_dashboard"."restriction_level",
- "posthog_dashboard"."quick_filter_ids",
- "posthog_dashboard"."customization",
- "posthog_dashboard"."deprecated_tags",
- "posthog_dashboard"."tags",
- "posthog_dashboard"."share_token",
- "posthog_dashboard"."is_shared"
+ SELECT "posthog_dashboard"."id" AS "id"
FROM "posthog_dashboard"
INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id")
WHERE (NOT ("posthog_dashboard"."deleted")
@@ -4651,11 +4492,14 @@
LIMIT 1)
OR ("posthog_team"."parent_team_id" IS NULL
AND "posthog_dashboard"."team_id" = 99999))
- AND "posthog_dashboard"."id" = 99999)
- LIMIT 21
+ AND "posthog_dashboard"."id" IN (1,
+ 2,
+ 3,
+ 4,
+ 5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.116
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.115
'''
SELECT COUNT(*) AS "__count"
FROM "posthog_dashboardtile"
@@ -4668,7 +4512,7 @@
AND "posthog_dashboardtile"."deleted" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.117
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.116
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -4701,7 +4545,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.118
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.117
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -4803,7 +4647,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.119
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.118
'''
SELECT "posthog_filesystem"."team_id",
"posthog_filesystem"."id",
@@ -4828,26 +4672,7 @@
AND "posthog_filesystem"."shortcut" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.12
- '''
- SELECT "posthog_sharingconfiguration"."id",
- "posthog_sharingconfiguration"."team_id",
- "posthog_sharingconfiguration"."dashboard_id",
- "posthog_sharingconfiguration"."insight_id",
- "posthog_sharingconfiguration"."recording_id",
- "posthog_sharingconfiguration"."notebook_id",
- "posthog_sharingconfiguration"."interviewee_context_id",
- "posthog_sharingconfiguration"."created_at",
- "posthog_sharingconfiguration"."enabled",
- "posthog_sharingconfiguration"."access_token",
- "posthog_sharingconfiguration"."expires_at",
- "posthog_sharingconfiguration"."settings",
- "posthog_sharingconfiguration"."password_required"
- FROM "posthog_sharingconfiguration"
- WHERE "posthog_sharingconfiguration"."dashboard_id" = 99999
- '''
-# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.120
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.119
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -4892,7 +4717,26 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.121
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.12
+ '''
+ SELECT "posthog_sharingconfiguration"."id",
+ "posthog_sharingconfiguration"."team_id",
+ "posthog_sharingconfiguration"."dashboard_id",
+ "posthog_sharingconfiguration"."insight_id",
+ "posthog_sharingconfiguration"."recording_id",
+ "posthog_sharingconfiguration"."notebook_id",
+ "posthog_sharingconfiguration"."interviewee_context_id",
+ "posthog_sharingconfiguration"."created_at",
+ "posthog_sharingconfiguration"."enabled",
+ "posthog_sharingconfiguration"."access_token",
+ "posthog_sharingconfiguration"."expires_at",
+ "posthog_sharingconfiguration"."settings",
+ "posthog_sharingconfiguration"."password_required"
+ FROM "posthog_sharingconfiguration"
+ WHERE "posthog_sharingconfiguration"."dashboard_id" = 99999
+ '''
+# ---
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.120
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -4994,7 +4838,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.122
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.121
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -5021,7 +4865,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.123
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.122
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -5048,7 +4892,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.124
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.123
'''
SELECT "posthog_insightvariable"."created_by_id",
"posthog_insightvariable"."created_at",
@@ -5067,7 +4911,7 @@
WHERE "posthog_insightvariable"."team_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.125
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.124
'''
SELECT "posthog_dashboardtile"."dashboard_id" AS "dashboard_id"
FROM "posthog_dashboardtile"
@@ -5078,7 +4922,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.126
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.125
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -5111,7 +4955,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.127
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.126
'''
SELECT "posthog_tag"."name" AS "tag__name"
FROM "posthog_taggeditem"
@@ -5119,7 +4963,7 @@
WHERE "posthog_taggeditem"."insight_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.128
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.127
'''
SELECT "posthog_user"."id",
"posthog_user"."password",
@@ -5165,7 +5009,7 @@
AND "posthog_user"."id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.129
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.128
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -5210,14 +5054,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.13
- '''
- SELECT COUNT(*) AS "__count"
- FROM "posthog_taggeditem"
- WHERE "posthog_taggeditem"."dashboard_id" = 99999
- '''
-# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.130
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.129
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -5358,7 +5195,14 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.131
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.13
+ '''
+ SELECT COUNT(*) AS "__count"
+ FROM "posthog_taggeditem"
+ WHERE "posthog_taggeditem"."dashboard_id" = 99999
+ '''
+# ---
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.130
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -5412,7 +5256,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.132
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.131
'''
SELECT "ee_accesscontrol"."id",
"ee_accesscontrol"."team_id",
@@ -5437,7 +5281,7 @@
AND "ee_accesscontrol"."team_id" = 99999))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.133
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.132
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -5489,7 +5333,7 @@
WHERE "posthog_organizationmembership"."user_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.134
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.133
'''
SELECT "ee_accesscontrol"."team_id" AS "team_id",
"ee_accesscontrol"."resource_id" AS "resource_id",
@@ -5502,7 +5346,7 @@
AND "posthog_team"."organization_id" IN ('00000000-0000-0000-0000-000000000000'::uuid))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.135
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.134
'''
SELECT "ee_role"."organization_id" AS "role__organization_id",
"ee_rolemembership"."role_id" AS "role_id"
@@ -5511,7 +5355,7 @@
WHERE "ee_rolemembership"."user_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.136
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.135
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -5614,7 +5458,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.137
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.136
'''
SELECT "posthog_sharingconfiguration"."id",
"posthog_sharingconfiguration"."team_id",
@@ -5637,7 +5481,7 @@
5 /* ... */)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.138
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.137
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -6000,7 +5844,7 @@
ORDER BY "posthog_dashboarditem"."order" ASC
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.139
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.138
'''
SELECT ("posthog_dashboardtile"."insight_id") AS "_prefetch_related_val_insight_id",
"posthog_dashboard"."id",
@@ -6042,23 +5886,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.14
- '''
- SELECT "posthog_filesystem"."id" AS "id",
- "posthog_filesystem"."path" AS "path"
- FROM "posthog_filesystem"
- WHERE (("posthog_filesystem"."surface" IS NULL
- OR "posthog_filesystem"."surface" = 'web')
- AND "posthog_filesystem"."ref" = '0001'
- AND "posthog_filesystem"."team_id" = 99999
- AND "posthog_filesystem"."type" = 'dashboard'
- AND NOT ("posthog_filesystem"."shortcut"
- AND "posthog_filesystem"."shortcut" IS NOT NULL))
- ORDER BY 1 ASC
- LIMIT 1
- '''
-# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.140
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.139
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -6089,7 +5917,23 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.141
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.14
+ '''
+ SELECT "posthog_filesystem"."id" AS "id",
+ "posthog_filesystem"."path" AS "path"
+ FROM "posthog_filesystem"
+ WHERE (("posthog_filesystem"."surface" IS NULL
+ OR "posthog_filesystem"."surface" = 'web')
+ AND "posthog_filesystem"."ref" = '0001'
+ AND "posthog_filesystem"."team_id" = 99999
+ AND "posthog_filesystem"."type" = 'dashboard'
+ AND NOT ("posthog_filesystem"."shortcut"
+ AND "posthog_filesystem"."shortcut" IS NOT NULL))
+ ORDER BY 1 ASC
+ LIMIT 1
+ '''
+# ---
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.140
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -6118,7 +5962,7 @@
2)/* ... */)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.142
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.141
'''
SELECT "posthog_taggeditem"."id",
"posthog_taggeditem"."tag_id",
@@ -6145,7 +5989,7 @@
5 /* ... */)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.143
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.142
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -6247,7 +6091,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.144
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.143
'''
SELECT "posthog_filesystem"."team_id",
"posthog_filesystem"."id",
@@ -6272,7 +6116,7 @@
AND "posthog_filesystem"."shortcut" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.145
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.144
'''
SELECT "posthog_filesystemshortcut"."id",
"posthog_filesystemshortcut"."team_id",
@@ -6295,7 +6139,7 @@
AND "posthog_filesystemshortcut"."href" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.146
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.145
'''
SELECT "posthog_insightvariable"."created_by_id",
"posthog_insightvariable"."created_at",
@@ -6314,7 +6158,7 @@
WHERE "posthog_insightvariable"."team_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.147
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.146
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -6678,7 +6522,7 @@
ORDER BY "posthog_dashboarditem"."order" ASC
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.148
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.147
'''
SELECT ("posthog_dashboardtile"."insight_id") AS "_prefetch_related_val_insight_id",
"posthog_dashboard"."id",
@@ -6720,7 +6564,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.149
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.148
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -6751,23 +6595,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.15
- '''
- SELECT "posthog_filesystem"."id" AS "id",
- "posthog_filesystem"."path" AS "path"
- FROM "posthog_filesystem"
- WHERE (("posthog_filesystem"."surface" IS NULL
- OR "posthog_filesystem"."surface" = 'web')
- AND "posthog_filesystem"."ref" = '0001'
- AND "posthog_filesystem"."team_id" = 99999
- AND "posthog_filesystem"."type" = 'dashboard'
- AND NOT ("posthog_filesystem"."shortcut"
- AND "posthog_filesystem"."shortcut" IS NOT NULL))
- ORDER BY 1 ASC
- LIMIT 1
- '''
-# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.150
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.149
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -6796,7 +6624,23 @@
2)/* ... */)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.151
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.15
+ '''
+ SELECT "posthog_filesystem"."id" AS "id",
+ "posthog_filesystem"."path" AS "path"
+ FROM "posthog_filesystem"
+ WHERE (("posthog_filesystem"."surface" IS NULL
+ OR "posthog_filesystem"."surface" = 'web')
+ AND "posthog_filesystem"."ref" = '0001'
+ AND "posthog_filesystem"."team_id" = 99999
+ AND "posthog_filesystem"."type" = 'dashboard'
+ AND NOT ("posthog_filesystem"."shortcut"
+ AND "posthog_filesystem"."shortcut" IS NOT NULL))
+ ORDER BY 1 ASC
+ LIMIT 1
+ '''
+# ---
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.150
'''
SELECT "posthog_taggeditem"."id",
"posthog_taggeditem"."tag_id",
@@ -6823,7 +6667,7 @@
5 /* ... */)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.152
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.151
'''
SELECT "posthog_alertconfiguration"."created_by_id",
"posthog_alertconfiguration"."created_at",
@@ -6904,7 +6748,7 @@
5 /* ... */)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.153
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.152
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -9034,28 +8878,7 @@
# ---
# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.50
'''
- SELECT "posthog_dashboard"."id",
- "posthog_dashboard"."name",
- "posthog_dashboard"."description",
- "posthog_dashboard"."team_id",
- "posthog_dashboard"."pinned",
- "posthog_dashboard"."created_at",
- "posthog_dashboard"."created_by_id",
- "posthog_dashboard"."deleted",
- "posthog_dashboard"."last_accessed_at",
- "posthog_dashboard"."last_refresh",
- "posthog_dashboard"."filters",
- "posthog_dashboard"."variables",
- "posthog_dashboard"."breakdown_colors",
- "posthog_dashboard"."data_color_theme_id",
- "posthog_dashboard"."creation_mode",
- "posthog_dashboard"."restriction_level",
- "posthog_dashboard"."quick_filter_ids",
- "posthog_dashboard"."customization",
- "posthog_dashboard"."deprecated_tags",
- "posthog_dashboard"."tags",
- "posthog_dashboard"."share_token",
- "posthog_dashboard"."is_shared"
+ SELECT "posthog_dashboard"."id" AS "id"
FROM "posthog_dashboard"
INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id")
WHERE (NOT ("posthog_dashboard"."deleted")
@@ -9066,49 +8889,14 @@
LIMIT 1)
OR ("posthog_team"."parent_team_id" IS NULL
AND "posthog_dashboard"."team_id" = 99999))
- AND "posthog_dashboard"."id" = 99999)
- LIMIT 21
+ AND "posthog_dashboard"."id" IN (1,
+ 2,
+ 3,
+ 4,
+ 5 /* ... */))
'''
# ---
# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.51
- '''
- SELECT "posthog_dashboard"."id",
- "posthog_dashboard"."name",
- "posthog_dashboard"."description",
- "posthog_dashboard"."team_id",
- "posthog_dashboard"."pinned",
- "posthog_dashboard"."created_at",
- "posthog_dashboard"."created_by_id",
- "posthog_dashboard"."deleted",
- "posthog_dashboard"."last_accessed_at",
- "posthog_dashboard"."last_refresh",
- "posthog_dashboard"."filters",
- "posthog_dashboard"."variables",
- "posthog_dashboard"."breakdown_colors",
- "posthog_dashboard"."data_color_theme_id",
- "posthog_dashboard"."creation_mode",
- "posthog_dashboard"."restriction_level",
- "posthog_dashboard"."quick_filter_ids",
- "posthog_dashboard"."customization",
- "posthog_dashboard"."deprecated_tags",
- "posthog_dashboard"."tags",
- "posthog_dashboard"."share_token",
- "posthog_dashboard"."is_shared"
- FROM "posthog_dashboard"
- INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id")
- WHERE (NOT ("posthog_dashboard"."deleted")
- AND ("posthog_dashboard"."team_id" =
- (SELECT U0."parent_team_id" AS "parent_team_id"
- FROM "posthog_team" U0
- WHERE U0."id" = 99999
- LIMIT 1)
- OR ("posthog_team"."parent_team_id" IS NULL
- AND "posthog_dashboard"."team_id" = 99999))
- AND "posthog_dashboard"."id" = 99999)
- LIMIT 21
- '''
-# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.52
'''
SELECT COUNT(*) AS "__count"
FROM "posthog_dashboardtile"
@@ -9121,7 +8909,7 @@
AND "posthog_dashboardtile"."deleted" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.53
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.52
'''
SELECT COUNT(*) AS "__count"
FROM "posthog_dashboardtile"
@@ -9134,7 +8922,7 @@
AND "posthog_dashboardtile"."deleted" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.54
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.53
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -9167,7 +8955,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.55
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.54
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -9269,7 +9057,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.56
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.55
'''
SELECT "posthog_filesystem"."team_id",
"posthog_filesystem"."id",
@@ -9294,7 +9082,7 @@
AND "posthog_filesystem"."shortcut" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.57
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.56
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -9339,7 +9127,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.58
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.57
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -9441,7 +9229,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.59
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.58
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -9468,20 +9256,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.6
- '''
- SELECT "ee_accesscontrol"."team_id" AS "team_id",
- "ee_accesscontrol"."resource_id" AS "resource_id",
- "ee_accesscontrol"."organization_member_id" AS "organization_member_id",
- "ee_accesscontrol"."role_id" AS "role_id",
- "ee_accesscontrol"."access_level" AS "access_level"
- FROM "ee_accesscontrol"
- INNER JOIN "posthog_team" ON ("ee_accesscontrol"."team_id" = "posthog_team"."id")
- WHERE ("ee_accesscontrol"."resource" = 'project'
- AND "posthog_team"."organization_id" IN ('00000000-0000-0000-0000-000000000000'::uuid))
- '''
-# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.60
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.59
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -9508,7 +9283,20 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.61
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.6
+ '''
+ SELECT "ee_accesscontrol"."team_id" AS "team_id",
+ "ee_accesscontrol"."resource_id" AS "resource_id",
+ "ee_accesscontrol"."organization_member_id" AS "organization_member_id",
+ "ee_accesscontrol"."role_id" AS "role_id",
+ "ee_accesscontrol"."access_level" AS "access_level"
+ FROM "ee_accesscontrol"
+ INNER JOIN "posthog_team" ON ("ee_accesscontrol"."team_id" = "posthog_team"."id")
+ WHERE ("ee_accesscontrol"."resource" = 'project'
+ AND "posthog_team"."organization_id" IN ('00000000-0000-0000-0000-000000000000'::uuid))
+ '''
+# ---
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.60
'''
SELECT "posthog_insightvariable"."created_by_id",
"posthog_insightvariable"."created_at",
@@ -9527,7 +9315,7 @@
WHERE "posthog_insightvariable"."team_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.62
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.61
'''
SELECT "posthog_dashboardtile"."dashboard_id" AS "dashboard_id"
FROM "posthog_dashboardtile"
@@ -9538,7 +9326,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.63
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.62
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -9571,7 +9359,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.64
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.63
'''
SELECT "posthog_tag"."name" AS "tag__name"
FROM "posthog_taggeditem"
@@ -9579,7 +9367,7 @@
WHERE "posthog_taggeditem"."insight_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.65
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.64
'''
SELECT "posthog_user"."id",
"posthog_user"."password",
@@ -9625,7 +9413,7 @@
AND "posthog_user"."id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.66
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.65
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -9670,7 +9458,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.67
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.66
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -9811,7 +9599,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.68
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.67
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -9865,7 +9653,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.69
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.68
'''
SELECT "ee_accesscontrol"."id",
"ee_accesscontrol"."team_id",
@@ -9890,16 +9678,7 @@
AND "ee_accesscontrol"."team_id" = 99999))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.7
- '''
- SELECT "ee_role"."organization_id" AS "role__organization_id",
- "ee_rolemembership"."role_id" AS "role_id"
- FROM "ee_rolemembership"
- INNER JOIN "ee_role" ON ("ee_rolemembership"."role_id" = "ee_role"."id")
- WHERE "ee_rolemembership"."user_id" = 99999
- '''
-# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.70
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.69
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -9951,7 +9730,16 @@
WHERE "posthog_organizationmembership"."user_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.71
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.7
+ '''
+ SELECT "ee_role"."organization_id" AS "role__organization_id",
+ "ee_rolemembership"."role_id" AS "role_id"
+ FROM "ee_rolemembership"
+ INNER JOIN "ee_role" ON ("ee_rolemembership"."role_id" = "ee_role"."id")
+ WHERE "ee_rolemembership"."user_id" = 99999
+ '''
+# ---
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.70
'''
SELECT "ee_accesscontrol"."team_id" AS "team_id",
"ee_accesscontrol"."resource_id" AS "resource_id",
@@ -9964,7 +9752,7 @@
AND "posthog_team"."organization_id" IN ('00000000-0000-0000-0000-000000000000'::uuid))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.72
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.71
'''
SELECT "ee_role"."organization_id" AS "role__organization_id",
"ee_rolemembership"."role_id" AS "role_id"
@@ -9973,30 +9761,9 @@
WHERE "ee_rolemembership"."user_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.73
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.72
'''
- SELECT "posthog_dashboard"."id",
- "posthog_dashboard"."name",
- "posthog_dashboard"."description",
- "posthog_dashboard"."team_id",
- "posthog_dashboard"."pinned",
- "posthog_dashboard"."created_at",
- "posthog_dashboard"."created_by_id",
- "posthog_dashboard"."deleted",
- "posthog_dashboard"."last_accessed_at",
- "posthog_dashboard"."last_refresh",
- "posthog_dashboard"."filters",
- "posthog_dashboard"."variables",
- "posthog_dashboard"."breakdown_colors",
- "posthog_dashboard"."data_color_theme_id",
- "posthog_dashboard"."creation_mode",
- "posthog_dashboard"."restriction_level",
- "posthog_dashboard"."quick_filter_ids",
- "posthog_dashboard"."customization",
- "posthog_dashboard"."deprecated_tags",
- "posthog_dashboard"."tags",
- "posthog_dashboard"."share_token",
- "posthog_dashboard"."is_shared"
+ SELECT "posthog_dashboard"."id" AS "id"
FROM "posthog_dashboard"
INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id")
WHERE (NOT ("posthog_dashboard"."deleted")
@@ -10007,11 +9774,14 @@
LIMIT 1)
OR ("posthog_team"."parent_team_id" IS NULL
AND "posthog_dashboard"."team_id" = 99999))
- AND "posthog_dashboard"."id" = 99999)
- LIMIT 21
+ AND "posthog_dashboard"."id" IN (1,
+ 2,
+ 3,
+ 4,
+ 5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.74
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.73
'''
SELECT COUNT(*) AS "__count"
FROM "posthog_dashboardtile"
@@ -10024,7 +9794,7 @@
AND "posthog_dashboardtile"."deleted" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.75
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.74
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -10057,7 +9827,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.76
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.75
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -10159,7 +9929,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.77
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.76
'''
SELECT "posthog_filesystem"."team_id",
"posthog_filesystem"."id",
@@ -10184,7 +9954,7 @@
AND "posthog_filesystem"."shortcut" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.78
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.77
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -10229,7 +9999,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.79
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.78
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -10331,23 +10101,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.8
- '''
- SELECT COUNT(*) AS "__count"
- FROM "posthog_dashboard"
- INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id")
- WHERE (NOT ("posthog_dashboard"."deleted")
- AND ("posthog_dashboard"."team_id" =
- (SELECT U0."parent_team_id" AS "parent_team_id"
- FROM "posthog_team" U0
- WHERE U0."id" = 99999
- LIMIT 1)
- OR ("posthog_team"."parent_team_id" IS NULL
- AND "posthog_dashboard"."team_id" = 99999))
- AND NOT "posthog_dashboard"."deleted")
- '''
-# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.80
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.79
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -10374,7 +10128,23 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.81
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.8
+ '''
+ SELECT COUNT(*) AS "__count"
+ FROM "posthog_dashboard"
+ INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id")
+ WHERE (NOT ("posthog_dashboard"."deleted")
+ AND ("posthog_dashboard"."team_id" =
+ (SELECT U0."parent_team_id" AS "parent_team_id"
+ FROM "posthog_team" U0
+ WHERE U0."id" = 99999
+ LIMIT 1)
+ OR ("posthog_team"."parent_team_id" IS NULL
+ AND "posthog_dashboard"."team_id" = 99999))
+ AND NOT "posthog_dashboard"."deleted")
+ '''
+# ---
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.80
'''
SELECT "posthog_dashboardtile"."id",
"posthog_dashboardtile"."dashboard_id",
@@ -10401,7 +10171,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.82
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.81
'''
SELECT "posthog_insightvariable"."created_by_id",
"posthog_insightvariable"."created_at",
@@ -10420,7 +10190,7 @@
WHERE "posthog_insightvariable"."team_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.83
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.82
'''
SELECT "posthog_dashboardtile"."dashboard_id" AS "dashboard_id"
FROM "posthog_dashboardtile"
@@ -10431,7 +10201,7 @@
AND "posthog_dashboardtile"."insight_id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.84
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.83
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -10464,7 +10234,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.85
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.84
'''
SELECT "posthog_tag"."name" AS "tag__name"
FROM "posthog_taggeditem"
@@ -10472,7 +10242,7 @@
WHERE "posthog_taggeditem"."insight_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.86
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.85
'''
SELECT "posthog_user"."id",
"posthog_user"."password",
@@ -10518,7 +10288,7 @@
AND "posthog_user"."id" = 99999)
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.87
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.86
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -10563,7 +10333,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.88
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.87
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -10704,7 +10474,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.89
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.88
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -10758,6 +10528,31 @@
LIMIT 21
'''
# ---
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.89
+ '''
+ SELECT "ee_accesscontrol"."id",
+ "ee_accesscontrol"."team_id",
+ "ee_accesscontrol"."access_level",
+ "ee_accesscontrol"."resource",
+ "ee_accesscontrol"."resource_id",
+ "ee_accesscontrol"."organization_member_id",
+ "ee_accesscontrol"."role_id",
+ "ee_accesscontrol"."created_by_id",
+ "ee_accesscontrol"."created_at",
+ "ee_accesscontrol"."updated_at",
+ "posthog_team"."organization_id" AS "_team_organization_id"
+ FROM "ee_accesscontrol"
+ INNER JOIN "posthog_team" ON ("ee_accesscontrol"."team_id" = "posthog_team"."id")
+ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id")
+ WHERE (("ee_accesscontrol"."organization_member_id" IS NULL
+ AND "ee_accesscontrol"."role_id" IS NULL
+ AND "ee_accesscontrol"."team_id" = 99999)
+ OR ("posthog_organizationmembership"."organization_id" = '00000000-0000-0000-0000-000000000000'::uuid
+ AND "posthog_organizationmembership"."user_id" = 99999
+ AND "ee_accesscontrol"."role_id" IS NULL
+ AND "ee_accesscontrol"."team_id" = 99999))
+ '''
+# ---
# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.9
'''
SELECT "posthog_team"."id",
@@ -10861,31 +10656,6 @@
'''
# ---
# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.90
- '''
- SELECT "ee_accesscontrol"."id",
- "ee_accesscontrol"."team_id",
- "ee_accesscontrol"."access_level",
- "ee_accesscontrol"."resource",
- "ee_accesscontrol"."resource_id",
- "ee_accesscontrol"."organization_member_id",
- "ee_accesscontrol"."role_id",
- "ee_accesscontrol"."created_by_id",
- "ee_accesscontrol"."created_at",
- "ee_accesscontrol"."updated_at",
- "posthog_team"."organization_id" AS "_team_organization_id"
- FROM "ee_accesscontrol"
- INNER JOIN "posthog_team" ON ("ee_accesscontrol"."team_id" = "posthog_team"."id")
- LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id")
- WHERE (("ee_accesscontrol"."organization_member_id" IS NULL
- AND "ee_accesscontrol"."role_id" IS NULL
- AND "ee_accesscontrol"."team_id" = 99999)
- OR ("posthog_organizationmembership"."organization_id" = '00000000-0000-0000-0000-000000000000'::uuid
- AND "posthog_organizationmembership"."user_id" = 99999
- AND "ee_accesscontrol"."role_id" IS NULL
- AND "ee_accesscontrol"."team_id" = 99999))
- '''
-# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.91
'''
SELECT "posthog_organizationmembership"."id",
"posthog_organizationmembership"."organization_id",
@@ -10937,7 +10707,7 @@
WHERE "posthog_organizationmembership"."user_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.92
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.91
'''
SELECT "ee_accesscontrol"."team_id" AS "team_id",
"ee_accesscontrol"."resource_id" AS "resource_id",
@@ -10950,7 +10720,7 @@
AND "posthog_team"."organization_id" IN ('00000000-0000-0000-0000-000000000000'::uuid))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.93
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.92
'''
SELECT "ee_role"."organization_id" AS "role__organization_id",
"ee_rolemembership"."role_id" AS "role_id"
@@ -10959,30 +10729,9 @@
WHERE "ee_rolemembership"."user_id" = 99999
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.94
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.93
'''
- SELECT "posthog_dashboard"."id",
- "posthog_dashboard"."name",
- "posthog_dashboard"."description",
- "posthog_dashboard"."team_id",
- "posthog_dashboard"."pinned",
- "posthog_dashboard"."created_at",
- "posthog_dashboard"."created_by_id",
- "posthog_dashboard"."deleted",
- "posthog_dashboard"."last_accessed_at",
- "posthog_dashboard"."last_refresh",
- "posthog_dashboard"."filters",
- "posthog_dashboard"."variables",
- "posthog_dashboard"."breakdown_colors",
- "posthog_dashboard"."data_color_theme_id",
- "posthog_dashboard"."creation_mode",
- "posthog_dashboard"."restriction_level",
- "posthog_dashboard"."quick_filter_ids",
- "posthog_dashboard"."customization",
- "posthog_dashboard"."deprecated_tags",
- "posthog_dashboard"."tags",
- "posthog_dashboard"."share_token",
- "posthog_dashboard"."is_shared"
+ SELECT "posthog_dashboard"."id" AS "id"
FROM "posthog_dashboard"
INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id")
WHERE (NOT ("posthog_dashboard"."deleted")
@@ -10993,11 +10742,14 @@
LIMIT 1)
OR ("posthog_team"."parent_team_id" IS NULL
AND "posthog_dashboard"."team_id" = 99999))
- AND "posthog_dashboard"."id" = 99999)
- LIMIT 21
+ AND "posthog_dashboard"."id" IN (1,
+ 2,
+ 3,
+ 4,
+ 5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.95
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.94
'''
SELECT COUNT(*) AS "__count"
FROM "posthog_dashboardtile"
@@ -11010,7 +10762,7 @@
AND "posthog_dashboardtile"."deleted" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.96
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.95
'''
SELECT "posthog_dashboard"."id",
"posthog_dashboard"."name",
@@ -11043,7 +10795,7 @@
5 /* ... */))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.97
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.96
'''
SELECT "posthog_team"."id",
"posthog_team"."uuid",
@@ -11145,7 +10897,7 @@
LIMIT 21
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.98
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.97
'''
SELECT "posthog_filesystem"."team_id",
"posthog_filesystem"."id",
@@ -11170,7 +10922,7 @@
AND "posthog_filesystem"."shortcut" IS NOT NULL))
'''
# ---
-# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.99
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.98
'''
SELECT "posthog_organization"."id",
"posthog_organization"."name",
@@ -11215,6 +10967,108 @@
LIMIT 21
'''
# ---
+# name: TestDashboard.test_loading_individual_dashboard_does_not_prefetch_all_possible_tiles.99
+ '''
+ SELECT "posthog_team"."id",
+ "posthog_team"."uuid",
+ "posthog_team"."organization_id",
+ "posthog_team"."parent_team_id",
+ "posthog_team"."project_id",
+ "posthog_team"."api_token",
+ "posthog_team"."app_urls",
+ "posthog_team"."name",
+ "posthog_team"."slack_incoming_webhook",
+ "posthog_team"."created_at",
+ "posthog_team"."updated_at",
+ "posthog_team"."anonymize_ips",
+ "posthog_team"."completed_snippet_onboarding",
+ "posthog_team"."has_completed_onboarding_for",
+ "posthog_team"."onboarding_tasks",
+ "posthog_team"."ingested_event",
+ "posthog_team"."ingested_production_event",
+ "posthog_team"."ingested_production_event_last_checked_at",
+ "posthog_team"."person_processing_opt_out",
+ "posthog_team"."secret_api_token",
+ "posthog_team"."secret_api_token_backup",
+ "posthog_team"."session_recording_opt_in",
+ "posthog_team"."session_recording_sample_rate",
+ "posthog_team"."session_recording_minimum_duration_milliseconds",
+ "posthog_team"."session_recording_linked_flag",
+ "posthog_team"."session_recording_network_payload_capture_config",
+ "posthog_team"."session_recording_masking_config",
+ "posthog_team"."session_recording_url_trigger_config",
+ "posthog_team"."session_recording_url_blocklist_config",
+ "posthog_team"."session_recording_event_trigger_config",
+ "posthog_team"."session_recording_trigger_match_type_config",
+ "posthog_team"."session_recording_trigger_groups",
+ "posthog_team"."session_replay_config",
+ "posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
+ "posthog_team"."conversations_enabled",
+ "posthog_team"."conversations_settings",
+ "posthog_team"."proactive_tasks_enabled",
+ "posthog_team"."survey_config",
+ "posthog_team"."surveys_opt_in",
+ "posthog_team"."product_tours_opt_in",
+ "posthog_team"."capture_console_log_opt_in",
+ "posthog_team"."capture_performance_opt_in",
+ "posthog_team"."capture_dead_clicks",
+ "posthog_team"."autocapture_opt_out",
+ "posthog_team"."autocapture_web_vitals_opt_in",
+ "posthog_team"."autocapture_web_vitals_allowed_metrics",
+ "posthog_team"."autocapture_exceptions_opt_in",
+ "posthog_team"."autocapture_exceptions_errors_to_ignore",
+ "posthog_team"."logs_settings",
+ "posthog_team"."llm_gateway_enabled_at",
+ "posthog_team"."llm_gateway_revoked_at",
+ "posthog_team"."llm_gateway_overspend_allowance_usd",
+ "posthog_team"."heatmaps_opt_in",
+ "posthog_team"."receive_org_level_activity_logs",
+ "posthog_team"."web_analytics_pre_aggregated_tables_enabled",
+ "posthog_team"."web_analytics_pre_aggregated_tables_version",
+ "posthog_team"."flags_persistence_default",
+ "posthog_team"."feature_flag_confirmation_enabled",
+ "posthog_team"."feature_flag_confirmation_message",
+ "posthog_team"."default_evaluation_environments_enabled",
+ "posthog_team"."require_evaluation_environment_tags",
+ "posthog_team"."default_evaluation_contexts_enabled",
+ "posthog_team"."require_evaluation_contexts",
+ "posthog_team"."session_recording_version",
+ "posthog_team"."signup_token",
+ "posthog_team"."is_demo",
+ "posthog_team"."access_control",
+ "posthog_team"."week_start_day",
+ "posthog_team"."inject_web_apps",
+ "posthog_team"."test_account_filters",
+ "posthog_team"."test_account_filters_default_checked",
+ "posthog_team"."path_cleaning_filters",
+ "posthog_team"."timezone",
+ "posthog_team"."data_attributes",
+ "posthog_team"."person_display_name_properties",
+ "posthog_team"."live_events_columns",
+ "posthog_team"."recording_domains",
+ "posthog_team"."human_friendly_comparison_periods",
+ "posthog_team"."cookieless_server_hash_mode",
+ "posthog_team"."primary_dashboard_id",
+ "posthog_team"."default_data_theme",
+ "posthog_team"."extra_settings",
+ "posthog_team"."modifiers",
+ "posthog_team"."correlation_config",
+ "posthog_team"."session_recording_retention_period_days",
+ "posthog_team"."external_data_workspace_id",
+ "posthog_team"."external_data_workspace_last_synced_at",
+ "posthog_team"."api_query_rate_limit",
+ "posthog_team"."drop_events_older_than",
+ "posthog_team"."base_currency",
+ "posthog_team"."experiment_recalculation_time",
+ "posthog_team"."default_experiment_confidence_level",
+ "posthog_team"."default_experiment_stats_method",
+ "posthog_team"."business_model"
+ FROM "posthog_team"
+ WHERE "posthog_team"."id" = 99999
+ LIMIT 21
+ '''
+# ---
# name: TestDashboard.test_retrieve_dashboard
'''
SELECT "posthog_filesystem"."team_id",
diff --git a/posthog/test/repo_invariants/test_pytest_module_collisions.py b/posthog/test/repo_invariants/test_pytest_module_collisions.py
index 537b6286d3c3..3a5a7219b0fd 100644
--- a/posthog/test/repo_invariants/test_pytest_module_collisions.py
+++ b/posthog/test/repo_invariants/test_pytest_module_collisions.py
@@ -65,7 +65,7 @@ CI_SESSIONS: dict[str, tuple[tuple[str, ...], tuple[str, ...]]] = {
(
"posthog/clickhouse",
"posthog/queries",
- "products/product_analytics/backend/api/test",
+ "products/product_analytics/backend/tests/api",
"posthog/api/test/dashboards",
"ee/clickhouse",
),
diff --git a/posthog/user_permissions.py b/posthog/user_permissions.py
index c9e63d798be4..e1e051034db1 100644
--- a/posthog/user_permissions.py
+++ b/posthog/user_permissions.py
@@ -5,6 +5,7 @@ from uuid import UUID
from posthog.constants import AvailableFeature
from posthog.models import Organization, OrganizationMembership, Team, User
+from products.dashboards.backend.facade.enums import PrivilegeLevel, RestrictionLevel
from products.dashboards.backend.models.dashboard import Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile
from products.product_analytics.backend.facade.models import Insight
@@ -99,12 +100,12 @@ class UserPermissions:
return {membership.organization_id: membership for membership in memberships}
@cached_property
- def dashboard_privileges(self) -> dict[int, Dashboard.PrivilegeLevel]:
+ def dashboard_privileges(self) -> dict[int, PrivilegeLevel]:
try:
from ee.models import DashboardPrivilege
rows = DashboardPrivilege.objects.filter(user=self.user).values_list("dashboard_id", "level")
- return {dashboard_id: cast(Dashboard.PrivilegeLevel, level) for dashboard_id, level in rows}
+ return {dashboard_id: cast(PrivilegeLevel, level) for dashboard_id, level in rows}
except ImportError:
return {}
@@ -277,11 +278,11 @@ class UserDashboardPermissions:
self.dashboard = dashboard
@cached_property
- def effective_restriction_level(self) -> Dashboard.RestrictionLevel:
+ def effective_restriction_level(self) -> RestrictionLevel:
return (
- Dashboard.RestrictionLevel(self.dashboard.restriction_level)
+ RestrictionLevel(self.dashboard.restriction_level)
if cast(Organization, self.p.current_organization).is_feature_available(AvailableFeature.ACCESS_CONTROL)
- else Dashboard.RestrictionLevel.EVERYONE_IN_PROJECT_CAN_EDIT
+ else RestrictionLevel.EVERYONE_IN_PROJECT_CAN_EDIT
)
@cached_property
@@ -299,24 +300,24 @@ class UserDashboardPermissions:
)
@cached_property
- def effective_privilege_level(self) -> Dashboard.PrivilegeLevel:
+ def effective_privilege_level(self) -> PrivilegeLevel:
if (
# Checks can be skipped if the dashboard in on the lowest restriction level
- self.effective_restriction_level == Dashboard.RestrictionLevel.EVERYONE_IN_PROJECT_CAN_EDIT
+ self.effective_restriction_level == RestrictionLevel.EVERYONE_IN_PROJECT_CAN_EDIT
# Users with restriction rights can do anything
or self.can_restrict
):
# Returning the highest access level if no checks needed
- return Dashboard.PrivilegeLevel.CAN_EDIT
+ return PrivilegeLevel.CAN_EDIT
# We return lowest access level if there's no explicit privilege for this user
- return self.p.dashboard_privileges.get(self.dashboard.pk, Dashboard.PrivilegeLevel.CAN_VIEW)
+ return self.p.dashboard_privileges.get(self.dashboard.pk, PrivilegeLevel.CAN_VIEW)
@cached_property
def can_edit(self) -> bool:
- if self.effective_restriction_level < Dashboard.RestrictionLevel.ONLY_COLLABORATORS_CAN_EDIT:
+ if self.effective_restriction_level < RestrictionLevel.ONLY_COLLABORATORS_CAN_EDIT:
return True
- return self.effective_privilege_level >= Dashboard.PrivilegeLevel.CAN_EDIT
+ return self.effective_privilege_level >= PrivilegeLevel.CAN_EDIT
class UserInsightPermissions:
@@ -325,21 +326,21 @@ class UserInsightPermissions:
self.insight = insight
@cached_property
- def effective_restriction_level(self) -> Dashboard.RestrictionLevel:
+ def effective_restriction_level(self) -> RestrictionLevel:
if len(self.insight_dashboards) == 0:
- return Dashboard.RestrictionLevel.EVERYONE_IN_PROJECT_CAN_EDIT
+ return RestrictionLevel.EVERYONE_IN_PROJECT_CAN_EDIT
return max(self.p.dashboard(dashboard).effective_restriction_level for dashboard in self.insight_dashboards)
@cached_property
- def effective_privilege_level(self) -> Dashboard.PrivilegeLevel:
+ def effective_privilege_level(self) -> PrivilegeLevel:
if len(self.insight_dashboards) == 0:
- return Dashboard.PrivilegeLevel.CAN_EDIT
+ return PrivilegeLevel.CAN_EDIT
if any(self.p.dashboard(dashboard).can_edit for dashboard in self.insight_dashboards):
- return Dashboard.PrivilegeLevel.CAN_EDIT
+ return PrivilegeLevel.CAN_EDIT
else:
- return Dashboard.PrivilegeLevel.CAN_VIEW
+ return PrivilegeLevel.CAN_VIEW
@cached_property
def insight_dashboards(self):
diff --git a/products/alerts/backend/facade/api.py b/products/alerts/backend/facade/api.py
index 5fda0c7efffe..dd0c5d485164 100644
--- a/products/alerts/backend/facade/api.py
+++ b/products/alerts/backend/facade/api.py
@@ -5,6 +5,7 @@ from typing import Any, Literal, cast
from zoneinfo import ZoneInfo
from django.db import transaction
+from django.db.models import Prefetch
from django.utils import timezone
import structlog
@@ -70,6 +71,35 @@ def insight_ids_with_alerts(insight_ids: Collection[int]) -> set[int]:
return set(AlertConfiguration.objects.filter(insight_id__in=insight_ids).values_list("insight_id", flat=True))
+def insight_alerts_prefetch(to_attr: str) -> Prefetch:
+ """A ``Prefetch`` loading an insight's alerts in the shape ``serialize_insight_alerts`` needs.
+
+ Callers add it to their insight queryset and read the alerts back off ``to_attr``. The
+ select_related/prefetch_related shape belongs here because it follows AlertSerializer:
+ that serializer emits threshold and subscribed_users per alert, so without them every
+ alert in the response costs two extra queries.
+ """
+ # Sets no team filter of its own: the prefetch is scoped by the insight queryset it is
+ # attached to, and an alert always belongs to its insight's team.
+ # nosemgrep: idor-lookup-without-team
+ queryset = AlertConfiguration.objects.select_related("created_by", "threshold").prefetch_related("subscribed_users")
+ return Prefetch("alertconfiguration_set", queryset=queryset, to_attr=to_attr)
+
+
+def delete_insight_alerts(insight_ids: Collection[int]) -> None:
+ """Delete the alerts pointing at the given insights.
+
+ Call this inside the transaction that deletes or hides the insights themselves, so an
+ insight can never come back without its alerts. Rows go one at a time rather than through a
+ queryset delete, because a queryset delete never calls ``AlertConfiguration.delete()``, and
+ ModelActivityMixin hangs its per-row activity logging off that override.
+ """
+ # Caller-supplied ids that are already team-scoped by the caller's own query.
+ # nosemgrep: idor-lookup-without-team
+ for alert in AlertConfiguration.objects.filter(insight_id__in=insight_ids):
+ alert.delete()
+
+
def serialize_insight_alerts(alerts: Collection[AlertConfiguration], context: dict[str, Any]) -> list[dict[str, Any]]:
"""Render an insight's alerts for the insight API response.
@@ -181,7 +211,9 @@ __all__ = [
"SlackSnoozeOutcome",
"build_alert_destination_config",
"create_alert_destination_hog_functions",
+ "delete_insight_alerts",
"get_alert_team_id",
+ "insight_alerts_prefetch",
"insight_ids_with_alerts",
"serialize_insight_alerts",
"snooze_alert_from_slack",
diff --git a/products/alerts/backend/facade/models.py b/products/alerts/backend/facade/models.py
deleted file mode 100644
index 4c85d73d5331..000000000000
--- a/products/alerts/backend/facade/models.py
+++ /dev/null
@@ -1,14 +0,0 @@
-"""
-Model-class wiring for alerts.
-
-Re-exports the ``AlertConfiguration``, ``AlertSubscription`` and ``Threshold`` model classes
-under the watched-models allowance (MODEL_CROSSINGS). The insight API prefetches an insight's
-alerts with a ``Prefetch`` queryset so rendering them costs no extra query, and soft-deletes
-them alongside the insight — ORM semantics a frozen contract cannot express. ``Threshold`` and
-``AlertSubscription`` hang off ``AlertConfiguration`` and cross with it, because the rendered
-alert carries its threshold and its subscribers.
-"""
-
-from products.alerts.backend.models.alert import AlertConfiguration, AlertSubscription, Threshold
-
-__all__ = ["AlertConfiguration", "AlertSubscription", "Threshold"]
diff --git a/products/architecture.md b/products/architecture.md
index 2ab11330ce51..6de67ca35eec 100644
--- a/products/architecture.md
+++ b/products/architecture.md
@@ -106,25 +106,19 @@ Two core registries are keyed by model class identity and are explicit, sanction
There the class crosses for registration only, core drives only the registry's mixin methods, and the model's module must stay in the product's contract-check inputs.
**The watched-models allowance** is the one further, deliberately temporary exception, for products whose models are load-bearing substrate that core and sibling products consume and cannot yet stop consuming.
-Five products hold entries.
+Two products hold entries.
`warehouse_sources`: core HogQL reads its warehouse table/schema/source models to build queryable tables.
`product_analytics`: `Insight`, `InsightVariable` and `InsightViewed`.
Core and seven products (alerts, dashboards, surveys, annotations, exports, customer_analytics, pulse) hold ForeignKeys or M2Ms into `Insight` — dashboard tiles, subscriptions and exported assets, sharing configurations, tagged items — and rely on cascade deletes, relation traversal, reverse relations, and queryset-typed access-control filtering that a frozen contract cannot express.
`InsightViewed` crosses for the view-tracking upsert (`update_or_create`) that shared-insight rendering and the demo generator perform.
The dashboards→product_analytics `DashboardTile.insight` FK and `Dashboard.insights` M2M-through cross into the product against §8's direction rule; that coupling is accepted under this entry until dashboards pursues its own isolation.
-`dashboards` (`Dashboard`, `DashboardTile`, `Text`), `alerts` (`AlertConfiguration`, `Threshold`, `AlertSubscription`) and `cohorts` (`Cohort`) are the same coupling read from the other side.
-An insight's API representation includes the dashboards it sits on and the alerts watching it, so the insight viewset resolves target dashboards through querysets, compares `Dashboard.PrivilegeLevel` off the model, serializes tiles with a `ModelSerializer`, and creates, soft-deletes and restores tiles through the soft-delete manager.
-It prefetches alerts with a `Prefetch` queryset so the render costs no extra query, and soft-deletes them when the insight goes; `Threshold` and `AlertSubscription` hang off `AlertConfiguration` and are rendered with it.
-`Cohort` crosses for its `DoesNotExist`, which the legacy query path raises from inside filter resolution and the viewset turns into a 400.
-None of the three products is narrowed today, so the allowance costs them nothing yet; it binds when they narrow, and it keeps each crossing named rather than hidden behind an unlinted facade re-export.
-Retiring them means moving the dashboard-membership and alert rendering out of `product_analytics`' presentation, which is a larger change than sealing the product was.
-
An allowance product's facade may hand out model classes defined under `backend/models/`, provided the whole model surface — `backend/models/` and `backend/migrations/` — stays in the `backend:contract-check` inputs, so any model or migration change still re-runs the full suite.
That is the same soundness contract wiring locations have; what it does not buy is isolation — the coupling to core remains, `hogli product:lint` keeps a standing warning on it, and the direction of travel is still facade functions returning contracts.
The list lives in `MODEL_CROSSINGS` (`tools/hogli-commands/hogli_commands/product/isolation.py`) and is keyed `(product, class)`, like the carve-outs above: a class that is not listed is a leak and blocks narrowing, so a product already on the list cannot grow a new crossing without a doctrine change.
It only shrinks.
Adding an entry requires amending this section to name the class and why it cannot yet be a contract.
+
**The consumer side is default-deny.**
A crossing class may appear in consumer code only in a shape that `hogli product:crossings` identifies as instance-free.
These shapes are allowed:
diff --git a/products/cohorts/backend/facade/models.py b/products/cohorts/backend/facade/models.py
deleted file mode 100644
index bc3a45726f62..000000000000
--- a/products/cohorts/backend/facade/models.py
+++ /dev/null
@@ -1,12 +0,0 @@
-"""
-Model-class wiring for cohorts.
-
-Re-exports the ``Cohort`` model class under the watched-models allowance (MODEL_CROSSINGS).
-The insight API's legacy query path raises ``Cohort.DoesNotExist`` from inside filter
-resolution and turns it into a 400 — catching a model's own exception needs the class, and
-the tests that cover that path build cohort rows through the manager.
-"""
-
-from products.cohorts.backend.models.cohort import Cohort
-
-__all__ = ["Cohort"]
diff --git a/products/dashboards/backend/api/dashboard.py b/products/dashboards/backend/api/dashboard.py
index d473e18640e9..5b1cb9b1f922 100644
--- a/products/dashboards/backend/api/dashboard.py
+++ b/products/dashboards/backend/api/dashboard.py
@@ -115,6 +115,8 @@ from products.dashboards.backend.api.widget_openapi_serializers import (
WidgetCatalogResponseSerializer,
)
from products.dashboards.backend.constants import DASHBOARD_GRID_COLUMN_COUNT, MAX_WIDGETS_BATCH_SIZE
+from products.dashboards.backend.facade.api import DashboardTileBasicSerializer
+from products.dashboards.backend.facade.enums import PrivilegeLevel, RestrictionLevel
from products.dashboards.backend.feature_flags import dashboard_customization_enabled, dashboard_widgets_enabled
from products.dashboards.backend.models.dashboard import (
DASHBOARD_GRID_COMPACTION_MODES,
@@ -157,7 +159,6 @@ from products.notifications.backend.facade.api import (
from products.product_analytics.backend.facade.models import Insight, InsightVariable
from products.product_analytics.backend.presentation.insight import (
INCLUDE_DASHBOARDS_PARAMETER,
- DashboardTileBasicSerializer,
InsightBasicSerializer,
InsightSerializer,
InsightViewSet,
@@ -1139,19 +1140,19 @@ class DashboardBasicSerializer(
"restriction_level": {"help_text": "Controls who can edit the dashboard."},
}
- def get_effective_restriction_level(self, dashboard: Dashboard) -> Dashboard.RestrictionLevel:
+ def get_effective_restriction_level(self, dashboard: Dashboard) -> RestrictionLevel:
if self.context.get("is_shared"):
- return Dashboard.RestrictionLevel.ONLY_COLLABORATORS_CAN_EDIT
+ return RestrictionLevel.ONLY_COLLABORATORS_CAN_EDIT
return self.user_permissions.dashboard(dashboard).effective_restriction_level
- def get_effective_privilege_level(self, dashboard: Dashboard) -> Dashboard.PrivilegeLevel:
+ def get_effective_privilege_level(self, dashboard: Dashboard) -> PrivilegeLevel:
if self.context.get("is_shared"):
- return Dashboard.PrivilegeLevel.CAN_VIEW
+ return PrivilegeLevel.CAN_VIEW
return self.user_permissions.dashboard(dashboard).effective_privilege_level
def get_access_control_version(self, dashboard: Dashboard) -> str:
# This effectively means that the dashboard they are using the old dashboard permissions
- if dashboard.restriction_level > Dashboard.RestrictionLevel.EVERYONE_IN_PROJECT_CAN_EDIT:
+ if dashboard.restriction_level > RestrictionLevel.EVERYONE_IN_PROJECT_CAN_EDIT:
return "v1"
return "v2"
diff --git a/products/dashboards/backend/facade/api.py b/products/dashboards/backend/facade/api.py
new file mode 100644
index 000000000000..ee6960e585cc
--- /dev/null
+++ b/products/dashboards/backend/facade/api.py
@@ -0,0 +1,330 @@
+"""
+Dashboard membership of an insight, for callers outside this product.
+
+An insight sits on a dashboard through a tile, and a tile is a dashboards row: the queries that
+find it, the permission checks that guard it, its JSON shape and its soft-delete semantics all
+belong here. The insight API passes ids and gets back ids, counts and rendered tile JSON, so it
+never has to hold the tile or dashboard model classes itself.
+
+Everything that writes runs inside the caller's transaction; each function says so where it
+matters. Refusals are raised as the error types defined here — the caller decides which HTTP
+response they become.
+"""
+
+from collections.abc import Collection, Sequence
+from typing import TYPE_CHECKING, Any
+
+from django.db.models import Exists, OuterRef, Prefetch, QuerySet
+from django.utils.timezone import now
+
+from pydantic.dataclasses import dataclass
+from rest_framework import serializers
+
+from posthog.api.sharing_publish_gate import check_can_add_insight_to_shared_dashboard
+from posthog.models.user import User
+from posthog.rbac.user_access_control import UserAccessControl
+from posthog.user_permissions import UserPermissions
+
+from products.dashboards.backend.facade.enums import PrivilegeLevel
+from products.dashboards.backend.models.dashboard import Dashboard
+from products.dashboards.backend.models.dashboard_tile import DashboardTile
+
+if TYPE_CHECKING:
+ from products.product_analytics.backend.facade.models import Insight
+
+
+class DashboardNotFound(Exception):
+ """A requested dashboard is not one this team can place an insight on."""
+
+
+class DashboardNotEditable(Exception):
+ """The requester may not change which insights sit on this dashboard."""
+
+ def __init__(self, dashboard_id: int) -> None:
+ super().__init__(str(dashboard_id))
+ self.dashboard_id = dashboard_id
+
+
+class CannotAddToDashboard(DashboardNotEditable):
+ """Raised while placing an insight on a dashboard the requester can only view."""
+
+
+class CannotRemoveFromDashboard(DashboardNotEditable):
+ """Raised while taking an insight off a dashboard the requester can only view."""
+
+
+@dataclass(frozen=True)
+class DashboardRef:
+ """A dashboard as insight payloads and activity logs refer to it."""
+
+ id: int
+ name: str | None
+
+
+@dataclass(frozen=True)
+class MembershipChange:
+ """What one membership write changed, for the caller's analytics events and activity log."""
+
+ added_dashboard_ids: tuple[int, ...]
+ removed_dashboard_ids: tuple[int, ...]
+ dashboards: tuple[DashboardRef, ...]
+
+
+# The tile shape an insight payload carries for each dashboard it sits on. No docstring: it would
+# land in the generated OpenAPI component as a description.
+class DashboardTileBasicSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = DashboardTile
+ fields = ["id", "dashboard_id", "deleted"]
+
+
+def _refs_in_given_order(dashboard_ids: Sequence[int]) -> tuple[DashboardRef, ...]:
+ # Callers pass ids they have already validated against the team; this reads names only.
+ # nosemgrep: idor-lookup-without-team
+ names = dict(Dashboard.objects.filter(id__in=dashboard_ids).values_list("id", "name"))
+ return tuple(
+ DashboardRef(id=dashboard_id, name=names[dashboard_id])
+ for dashboard_id in dashboard_ids
+ if dashboard_id in names
+ )
+
+
+def unknown_dashboard_ids(dashboard_ids: Collection[int], *, team_id: int) -> list[int]:
+ """Which of these ids are not a live dashboard of this team, in the order they were given.
+
+ Live means not soft-deleted, so an id that used to work stops validating once its dashboard
+ is deleted.
+ """
+ known = set(Dashboard.objects.filter(team_id=team_id, id__in=dashboard_ids).values_list("id", flat=True))
+ return [dashboard_id for dashboard_id in dict.fromkeys(dashboard_ids) if dashboard_id not in known]
+
+
+def active_tile_count(dashboard_id: int) -> int:
+ """How many live tiles a dashboard carries, for the per-dashboard insight limit."""
+ # The caller resolved this id through the team-scoped dashboards field first.
+ # nosemgrep: idor-lookup-without-team
+ return DashboardTile.objects.filter(dashboard_id=dashboard_id).exclude(deleted=True).count()
+
+
+def tile_ids_prefetch() -> Prefetch:
+ """Prefetch of an insight's tiles carrying only the columns a basic insight payload renders."""
+ return Prefetch(
+ "dashboard_tiles",
+ queryset=DashboardTile.objects.only("id", "dashboard_id", "deleted", "insight_id"),
+ )
+
+
+def tile_permissions_prefetch() -> Prefetch:
+ """Prefetch of an insight's tiles with the joins the dashboard permission checks read."""
+ return Prefetch(
+ "dashboard_tiles",
+ queryset=DashboardTile.objects.select_related("dashboard__team__organization"),
+ )
+
+
+def insight_has_listed_tile() -> Exists:
+ """Subquery over insights: this insight has a tile on a dashboard the UI lists."""
+ return Exists(DashboardTile.objects.filter(insight=OuterRef("pk")).exclude(dashboard__creation_mode="unlisted"))
+
+
+def insight_ids_on_dashboard(dashboard_id: int) -> QuerySet:
+ """Ids of the insights with a tile on this dashboard, as a subquery for `id__in`."""
+ # Filtering a list the caller has already scoped to its own team.
+ # nosemgrep: idor-lookup-without-team
+ return DashboardTile.objects.filter(dashboard__id=dashboard_id).values_list("insight__id", flat=True).all()
+
+
+def tile_for_insight_on_dashboard(*, insight_id: int, dashboard_id: int | str) -> DashboardTile | None:
+ """The tile that places one insight on one dashboard, with its dashboard loaded.
+
+ Returns a tile whatever the requester may see: the caller checks dashboard access on the
+ result, because the checks differ between session and sharing-token callers.
+ """
+ # nosemgrep: idor-lookup-without-team
+ return (
+ DashboardTile.objects.filter(dashboard__id=dashboard_id, insight__id=insight_id)
+ .select_related("dashboard")
+ .first()
+ )
+
+
+def tile_for_render(*, insight: "Insight", dashboard: Dashboard) -> DashboardTile | None:
+ """The tile an insight renders as on a dashboard, with the relations the render reads."""
+ return DashboardTile.dashboard_queryset(DashboardTile.objects.filter(insight=insight, dashboard=dashboard)).first()
+
+
+def hide_tiles_for_insights(insight_ids: Collection[int]) -> None:
+ """Soft-delete every tile of these insights, tiles already soft-deleted included.
+
+ Run inside the caller's transaction: it is one half of soft-deleting the insights themselves.
+ """
+ DashboardTile.objects_including_soft_deleted.filter(insight_id__in=insight_ids).update(deleted=True)
+
+
+def restore_tiles_for_insights(insight_ids: Collection[int], *, user_permissions: UserPermissions) -> None:
+ """Re-activate soft-deleted tiles of these insights, on live dashboards the requester may edit.
+
+ Run inside the caller's transaction: it is one half of restoring the insights themselves.
+ Mirrors the per-dashboard CAN_EDIT check membership updates apply, so a restore can't force an
+ insight back onto a dashboard the requester can only view. Tiles removed before the delete may
+ also reappear; acceptable for the immediate-undo case this backs.
+ """
+ candidate_tiles = DashboardTile.objects_including_soft_deleted.filter(
+ insight_id__in=insight_ids, deleted=True, dashboard__deleted=False
+ ).select_related("dashboard")
+ restorable_tile_ids = [
+ tile.id
+ for tile in candidate_tiles
+ if user_permissions.dashboard(tile.dashboard).effective_privilege_level == PrivilegeLevel.CAN_EDIT
+ ]
+ if restorable_tile_ids:
+ DashboardTile.objects_including_soft_deleted.filter(id__in=restorable_tile_ids).update(deleted=False)
+
+
+class InsightTilePlacement:
+ """Dashboards cleared to receive a tile for one insight.
+
+ Built by `plan_insight_tile_placement` before the insight row exists, so a refusal can't leave
+ an orphaned insight behind, then applied with `create_tiles` once it does. Holding the
+ dashboards it read is what keeps applying free of a second read.
+ """
+
+ def __init__(self, dashboards: list[Dashboard]) -> None:
+ self._dashboards = dashboards
+
+ @property
+ def dashboards(self) -> tuple[DashboardRef, ...]:
+ return tuple(DashboardRef(id=dashboard.id, name=dashboard.name) for dashboard in self._dashboards)
+
+ def create_tiles(self, insight: "Insight") -> tuple[DashboardRef, ...]:
+ """Place the insight on every cleared dashboard, and report which ones those were."""
+ for dashboard in self._dashboards:
+ DashboardTile.objects.create(
+ insight=insight, dashboard=dashboard, team_id=dashboard.team_id, last_refresh=now()
+ )
+ return self.dashboards
+
+
+def plan_insight_tile_placement(
+ *,
+ dashboard_ids: Sequence[int],
+ team_id: int,
+ query: Any,
+ user: User,
+ user_permissions: UserPermissions,
+ user_access_control: UserAccessControl | None,
+) -> InsightTilePlacement:
+ """Check that an insight carrying `query` may be placed on these dashboards.
+
+ Raises `CannotAddToDashboard` when the requester can only view one of them, `DashboardNotFound`
+ when one belongs to another team, and the shared-dashboard publish gate's own ValidationError
+ when the query would reach further through a dashboard's public link than the requester can.
+ """
+ # nosemgrep: idor-lookup-without-team (team check below)
+ found = {dashboard.id: dashboard for dashboard in Dashboard.objects.filter(id__in=dashboard_ids)}
+ dashboards = [found[dashboard_id] for dashboard_id in dict.fromkeys(dashboard_ids) if dashboard_id in found]
+ for dashboard in dashboards:
+ # Adding a tile is an edit of the dashboard, so a restricted dashboard the requester
+ # can't edit must not be writable here either.
+ if user_permissions.dashboard(dashboard).effective_privilege_level != PrivilegeLevel.CAN_EDIT:
+ raise CannotAddToDashboard(dashboard.id)
+ if dashboard.team_id != team_id:
+ raise DashboardNotFound
+ # The dashboard's public link must not expose a query the editor can't run.
+ check_can_add_insight_to_shared_dashboard(user, dashboard, query, user_access_control)
+ return InsightTilePlacement(dashboards)
+
+
+def update_insight_dashboard_membership(
+ *,
+ insight: "Insight",
+ dashboard_ids: Sequence[int],
+ user: User,
+ user_permissions: UserPermissions,
+ user_access_control: UserAccessControl | None,
+) -> MembershipChange | None:
+ """Move an insight on and off dashboards until it sits on exactly `dashboard_ids`.
+
+ Returns None when it already does. Adding restores the insight's previously removed tile
+ rather than creating a second one; removing soft-deletes the tile so the same restore works
+ next time. Refusals raise `CannotAddToDashboard`, `CannotRemoveFromDashboard` or
+ `DashboardNotFound` before anything else is written for that dashboard.
+
+ Run inside the caller's transaction — a refusal partway through must not leave the insight on
+ some of the dashboards but not others.
+
+ Reads `insight.dashboard_tiles`, and leaves that prefetch stale: the writes below go through
+ separate querysets, so a caller that serializes the insight afterwards has to drop the
+ prefetched relation first.
+ """
+ old_dashboard_ids = [tile.dashboard_id for tile in insight.dashboard_tiles.all()]
+ new_dashboard_ids = list(dashboard_ids)
+ if sorted(old_dashboard_ids) == sorted(new_dashboard_ids):
+ return None
+
+ ids_to_add = [dashboard_id for dashboard_id in new_dashboard_ids if dashboard_id not in old_dashboard_ids]
+ ids_to_remove = [dashboard_id for dashboard_id in old_dashboard_ids if dashboard_id not in new_dashboard_ids]
+
+ added_dashboard_ids: list[int] = []
+ # nosemgrep: idor-lookup-without-team (team check after lookup)
+ for dashboard in Dashboard.objects.filter(id__in=ids_to_add):
+ # Does the requester have permission to add to this dashboard? If it is restricted, the
+ # patch would otherwise make the insight restricted too.
+ if user_permissions.dashboard(dashboard).effective_privilege_level != PrivilegeLevel.CAN_EDIT:
+ raise CannotAddToDashboard(dashboard.id)
+
+ if dashboard.team != insight.team:
+ raise DashboardNotFound
+
+ # The dashboard's public link must not expose a query the editor can't run.
+ check_can_add_insight_to_shared_dashboard(user, dashboard, insight.query, user_access_control)
+
+ tile, _ = DashboardTile.objects_including_soft_deleted.get_or_create(insight=insight, dashboard=dashboard)
+ if tile.deleted:
+ tile.deleted = False
+ tile.save()
+
+ added_dashboard_ids.append(dashboard.id)
+
+ removed_dashboard_ids: list[int] = []
+ if ids_to_remove:
+ # nosemgrep: idor-lookup-without-team (team check after lookup)
+ for dashboard in Dashboard.objects.filter(id__in=ids_to_remove):
+ if user_permissions.dashboard(dashboard).effective_privilege_level != PrivilegeLevel.CAN_EDIT:
+ raise CannotRemoveFromDashboard(dashboard.id)
+
+ # Capture the still-active tiles before soft-deleting so the caller can report one
+ # removal per tile that is actually removed.
+ tiles_to_remove = list(DashboardTile.objects.filter(dashboard_id__in=ids_to_remove, insight=insight))
+ DashboardTile.objects.filter(dashboard_id__in=ids_to_remove, insight=insight).update(deleted=True)
+ removed_dashboard_ids = [tile.dashboard_id for tile in tiles_to_remove]
+
+ return MembershipChange(
+ added_dashboard_ids=tuple(added_dashboard_ids),
+ removed_dashboard_ids=tuple(removed_dashboard_ids),
+ dashboards=_refs_in_given_order(new_dashboard_ids),
+ )
+
+
+__all__ = [
+ "CannotAddToDashboard",
+ "CannotRemoveFromDashboard",
+ "DashboardNotEditable",
+ "DashboardNotFound",
+ "DashboardRef",
+ "DashboardTileBasicSerializer",
+ "InsightTilePlacement",
+ "MembershipChange",
+ "active_tile_count",
+ "hide_tiles_for_insights",
+ "insight_has_listed_tile",
+ "insight_ids_on_dashboard",
+ "plan_insight_tile_placement",
+ "restore_tiles_for_insights",
+ "tile_for_insight_on_dashboard",
+ "tile_for_render",
+ "tile_ids_prefetch",
+ "tile_permissions_prefetch",
+ "unknown_dashboard_ids",
+ "update_insight_dashboard_membership",
+]
diff --git a/products/dashboards/backend/facade/enums.py b/products/dashboards/backend/facade/enums.py
index 7b9f7d4d2e07..e340e55fa5a9 100644
--- a/products/dashboards/backend/facade/enums.py
+++ b/products/dashboards/backend/facade/enums.py
@@ -4,13 +4,37 @@ Shared enums for the dashboards product.
``DashboardAccessMethod`` labels how a dashboard render was reached. It lives in the facade
rather than in ``backend/access.py`` because the insight API tags its own cache metrics with
it, and a data type that crosses the product boundary belongs here.
+
+``RestrictionLevel`` and ``PrivilegeLevel`` are the collaboration levels the ``Dashboard`` model
+stores and every caller compares against. They are defined here for the same reason: the insight
+API reports an insight's effective levels and gates dashboard edits on ``CAN_EDIT``. The model
+keeps ``Dashboard.RestrictionLevel`` / ``Dashboard.PrivilegeLevel`` as aliases of these.
"""
from enum import StrEnum
+from django.db import models
+
class DashboardAccessMethod(StrEnum):
HUMAN = "human"
SHARED = "shared"
EMBEDDED = "embedded"
API = "api"
+
+
+class RestrictionLevel(models.IntegerChoices):
+ """Collaboration restriction level (which is a dashboard setting). Sync with PrivilegeLevel."""
+
+ EVERYONE_IN_PROJECT_CAN_EDIT = 21, "Everyone in the project can edit"
+ ONLY_COLLABORATORS_CAN_EDIT = (
+ 37,
+ "Only those invited to this dashboard can edit",
+ )
+
+
+class PrivilegeLevel(models.IntegerChoices):
+ """Collaboration privilege level (which is a user property). Sync with RestrictionLevel."""
+
+ CAN_VIEW = 21, "Can view dashboard"
+ CAN_EDIT = 37, "Can edit dashboard"
diff --git a/products/dashboards/backend/facade/models.py b/products/dashboards/backend/facade/models.py
deleted file mode 100644
index a81423d8ac37..000000000000
--- a/products/dashboards/backend/facade/models.py
+++ /dev/null
@@ -1,15 +0,0 @@
-"""
-Model-class wiring for dashboards.
-
-Re-exports the ``Dashboard``, ``DashboardTile`` and ``Text`` model classes for cross-product
-consumers under the watched-models allowance (MODEL_CROSSINGS). The insight API renders an
-insight's dashboard membership: it resolves target dashboards through querysets, reads
-privilege levels off the model, serializes tiles with a ``ModelSerializer``, and creates,
-soft-deletes and restores tiles — ORM semantics a frozen contract cannot express. ``Text``
-crosses with ``DashboardTile`` because a tile carries either an insight or a text block.
-"""
-
-from products.dashboards.backend.models.dashboard import Dashboard
-from products.dashboards.backend.models.dashboard_tile import DashboardTile, Text
-
-__all__ = ["Dashboard", "DashboardTile", "Text"]
diff --git a/products/dashboards/backend/models/dashboard.py b/products/dashboards/backend/models/dashboard.py
index b613c04c9ffc..30fdac4f3499 100644
--- a/products/dashboards/backend/models/dashboard.py
+++ b/products/dashboards/backend/models/dashboard.py
@@ -11,6 +11,8 @@ from posthog.models.file_system.file_system_representation import FileSystemRepr
from posthog.models.utils import RootTeamManager, RootTeamMixin, sane_repr
from posthog.utils import absolute_uri
+from products.dashboards.backend.facade import enums
+
if TYPE_CHECKING:
from posthog.models.team import Team
@@ -47,20 +49,10 @@ class Dashboard(FileSystemSyncMixin, ModelActivityMixin, RootTeamMixin, models.M
"Unlisted (product-embedded)",
) # Product dashboards (e.g. AI observability) - hidden from general lists, accessed via tag queries
- class RestrictionLevel(models.IntegerChoices):
- """Collaboration restriction level (which is a dashboard setting). Sync with PrivilegeLevel."""
-
- EVERYONE_IN_PROJECT_CAN_EDIT = 21, "Everyone in the project can edit"
- ONLY_COLLABORATORS_CAN_EDIT = (
- 37,
- "Only those invited to this dashboard can edit",
- )
-
- class PrivilegeLevel(models.IntegerChoices):
- """Collaboration privilege level (which is a user property). Sync with RestrictionLevel."""
-
- CAN_VIEW = 21, "Can view dashboard"
- CAN_EDIT = 37, "Can edit dashboard"
+ # Aliases of the facade enums, which is where callers outside this product read them from.
+ # Kept on the model so `Dashboard.PrivilegeLevel` and the `choices=` below stay unchanged.
+ RestrictionLevel = enums.RestrictionLevel
+ PrivilegeLevel = enums.PrivilegeLevel
name = models.CharField(max_length=400, null=True, blank=True)
description = models.TextField(blank=True)
diff --git a/products/dashboards/backend/test/test_insight_tile_facade.py b/products/dashboards/backend/test/test_insight_tile_facade.py
new file mode 100644
index 000000000000..d519aa8a6cc0
--- /dev/null
+++ b/products/dashboards/backend/test/test_insight_tile_facade.py
@@ -0,0 +1,38 @@
+from posthog.test.base import APIBaseTest
+
+from parameterized import parameterized
+
+from posthog.models.team import Team
+
+from products.dashboards.backend.facade.api import unknown_dashboard_ids
+from products.dashboards.backend.models.dashboard import Dashboard
+
+
+class TestUnknownDashboardIds(APIBaseTest):
+ def setUp(self) -> None:
+ super().setUp()
+ self.live = Dashboard.objects.create(team=self.team, name="live")
+ self.soft_deleted = Dashboard.objects.create(team=self.team, name="gone", deleted=True)
+ other_team = Team.objects.create(organization=self.organization)
+ self.other_team_dashboard = Dashboard.objects.create(team=other_team, name="theirs")
+
+ @parameterized.expand(
+ [
+ ("live_dashboard", "live", []),
+ ("soft_deleted_dashboard", "soft_deleted", ["soft_deleted"]),
+ ("another_teams_dashboard", "other_team_dashboard", ["other_team_dashboard"]),
+ ]
+ )
+ def test_reports_ids_this_team_cannot_place_a_tile_on(
+ self, _name: str, dashboard_attr: str, expected_unknown_attrs: list[str]
+ ) -> None:
+ dashboard_id = getattr(self, dashboard_attr).id
+ expected = [getattr(self, attr).id for attr in expected_unknown_attrs]
+
+ assert unknown_dashboard_ids([dashboard_id], team_id=self.team.id) == expected
+
+ def test_reports_an_id_that_does_not_exist(self) -> None:
+ assert unknown_dashboard_ids([self.live.id, 9_999_999], team_id=self.team.id) == [9_999_999]
+
+ def test_reports_a_repeated_unknown_id_once(self) -> None:
+ assert unknown_dashboard_ids([9_999_999, 9_999_999], team_id=self.team.id) == [9_999_999]
diff --git a/products/model_crossing_uses_baseline.txt b/products/model_crossing_uses_baseline.txt
index 47cc200e388b..9689aab3da6e 100644
--- a/products/model_crossing_uses_baseline.txt
+++ b/products/model_crossing_uses_baseline.txt
@@ -6,174 +6,6 @@
# A new line needs a doctrine amendment, not a baseline edit.
#
# Regenerate: bin/hogli product:crossings --all --write-baseline
-alerts.AlertConfiguration ee.hogai.context.entity_search.context in-collection 1
-alerts.AlertConfiguration posthog.temporal.ai.anomaly_investigation.workflow instance-many(aget) 1
-alerts.AlertConfiguration posthog.temporal.alerts.activities instance-many(only) 1
-alerts.AlertConfiguration posthog.temporal.alerts.activities instance-single 2
-alerts.AlertConfiguration posthog.temporal.alerts.activities lock 3
-alerts.AlertConfiguration posthog.temporal.alerts.activities other(Attribute:interval_entitlement_error) 1
-alerts.AlertConfiguration products.dashboards.backend.api.dashboard prefetch 1
-alerts.AlertConfiguration products.product_analytics.backend.presentation.insight instance-many(filter) 1
-alerts.AlertConfiguration products.product_analytics.backend.presentation.insight prefetch 1
-alerts.AlertConfiguration products.pulse.backend.generation.persist instance-many(filter) 1
-alerts.AlertConfiguration products.pulse.backend.generation.persist other(BinOp) 1
-alerts.AlertConfiguration products.pulse.backend.sources.resource_health instance-many(order_by) 1
-alerts.AlertConfiguration products.signals.backend.scout_harness.profile.builders instance-many(filter) 1
-alerts.AlertSubscription posthog.models.organization write(delete) 1
-cohorts.Cohort ee.benchmarks.benchmarks instance-single 1
-cohorts.Cohort ee.benchmarks.benchmarks write(create) 1
-cohorts.Cohort ee.hogai.context.entity_search.context in-collection 1
-cohorts.Cohort posthog.admin.admins.cohort_admin passed-as-class(register) 1
-cohorts.Cohort posthog.api.cohort construct 1
-cohorts.Cohort posthog.api.cohort drf-model-serializer 2
-cohorts.Cohort posthog.api.cohort in-collection 2
-cohorts.Cohort posthog.api.cohort instance-many(all) 1
-cohorts.Cohort posthog.api.cohort instance-many(filter) 1
-cohorts.Cohort posthog.api.cohort instance-many(order_by) 1
-cohorts.Cohort posthog.api.cohort instance-many(to_dict) 1
-cohorts.Cohort posthog.api.cohort instance-single 4
-cohorts.Cohort posthog.api.cohort passed-as-class(cast) 4
-cohorts.Cohort posthog.api.cohort write(create) 1
-cohorts.Cohort posthog.api.person instance-many(filter) 1
-cohorts.Cohort posthog.api.search in-collection 1
-cohorts.Cohort posthog.cdp.filters instance-single 1
-cohorts.Cohort posthog.dags.backfill_internal_test_users_cohort construct 1
-cohorts.Cohort posthog.dags.backfill_internal_test_users_cohort other(Attribute:compute_condition_type) 1
-cohorts.Cohort posthog.dags.backfill_internal_test_users_cohort write(bulk_create) 1
-cohorts.Cohort posthog.hogql.functions.cohort instance-single 1
-cohorts.Cohort posthog.hogql.property instance-single 1
-cohorts.Cohort posthog.hogql_queries.hogql_cohort_query instance-single 2
-cohorts.Cohort posthog.hogql_queries.insights.funnels.base instance-many(filter) 2
-cohorts.Cohort posthog.hogql_queries.insights.funnels.utils instance-many(name) 1
-cohorts.Cohort posthog.hogql_queries.insights.trends.trends_query_runner instance-many(name) 2
-cohorts.Cohort posthog.management.commands.calculate_cohort instance-single 1
-cohorts.Cohort posthog.management.commands.resave_cohorts instance-many(order_by) 1
-cohorts.Cohort posthog.management.commands.resave_cohorts other(Attribute:compute_condition_type) 1
-cohorts.Cohort posthog.management.commands.survey_cohort_bytecode_stl instance-many(filter) 1
-cohorts.Cohort posthog.middleware instance-many(filter) 1
-cohorts.Cohort posthog.models.file_system.unfiled_file_saver in-collection 1
-cohorts.Cohort posthog.models.filters.mixins.simplify instance-single 1
-cohorts.Cohort posthog.models.property.util instance-single 2
-cohorts.Cohort posthog.models.resource_transfer.visitors.cohort other(Return) 1
-cohorts.Cohort posthog.models.resource_transfer.visitors.cohort passed-as-class(build_edges_for_ids) 1
-cohorts.Cohort posthog.models.resource_transfer.visitors.experiment passed-as-class(build_edges_for_ids) 1
-cohorts.Cohort posthog.models.resource_transfer.visitors.experiment_holdout passed-as-class(build_edges_for_ids) 1
-cohorts.Cohort posthog.models.resource_transfer.visitors.experiment_saved_metric passed-as-class(build_edges_for_ids) 1
-cohorts.Cohort posthog.models.resource_transfer.visitors.feature_flag passed-as-class(build_edges_for_ids) 1
-cohorts.Cohort posthog.models.resource_transfer.visitors.insight passed-as-class(build_edges_for_ids) 1
-cohorts.Cohort posthog.models.resource_transfer.visitors.survey passed-as-class(build_edges_for_ids) 1
-cohorts.Cohort posthog.queries.person_query instance-single 1
-cohorts.Cohort posthog.session_recordings.queries.sub_queries.cohort_subquery instance-single 1
-cohorts.Cohort posthog.tasks.calculate_cohort instance-many(exclude) 3
-cohorts.Cohort posthog.tasks.calculate_cohort instance-many(filter) 1
-cohorts.Cohort posthog.tasks.calculate_cohort instance-single 6
-cohorts.Cohort posthog.tasks.calculate_cohort write(update) 1
-cohorts.Cohort products.actions.backend.api.action instance-many(extra) 1
-cohorts.Cohort products.cdp.backend.tasks.hog_functions instance-single 1
-cohorts.Cohort products.demo.backend.logic.matrix.manager instance-many(filter) 1
-cohorts.Cohort products.demo.backend.logic.products.hedgebox.matrix write(create) 1
-cohorts.Cohort products.demo.backend.logic.products.spikegpt.matrix write(create) 1
-cohorts.Cohort products.error_tracking.backend.logic.issue_mutations instance-single 1
-cohorts.Cohort products.experiments.backend.admin.experiment_admin instance-many(filter) 1
-cohorts.Cohort products.experiments.backend.experiment_service instance-many(filter) 1
-cohorts.Cohort products.experiments.backend.experiment_service write(create) 1
-cohorts.Cohort products.feature_flags.backend.api.feature_flag instance-many(filter) 1
-cohorts.Cohort products.feature_flags.backend.api.feature_flag instance-single 1
-cohorts.Cohort products.feature_flags.backend.api.feature_flag prefetch 1
-cohorts.Cohort products.feature_flags.backend.api.organization_feature_flag instance-single 2
-cohorts.Cohort products.feature_flags.backend.flag_version_sync instance-many(filter) 1
-cohorts.Cohort products.feature_flags.backend.flag_version_sync instance-many(manager) 1
-cohorts.Cohort products.feature_flags.backend.flag_version_sync other(keyword) 2
-cohorts.Cohort products.feature_flags.backend.flags_cache instance-many(filter) 1
-cohorts.Cohort products.feature_flags.backend.flags_cache other(keyword) 2
-cohorts.Cohort products.feature_flags.backend.local_evaluation instance-many(select_related) 1
-cohorts.Cohort products.feature_flags.backend.local_evaluation other(keyword) 2
-cohorts.Cohort products.feature_flags.backend.models.feature_flag instance-single 1
-cohorts.Cohort products.replay_vision.backend.impact write(create) 1
-cohorts.Cohort products.signals.backend.scout_harness.profile.builders instance-many(filter) 1
-cohorts.Cohort products.workflows.backend.api.hog_flow instance-single 1
-dashboards.Dashboard ee.api.dashboard_collaborator instance-single 2
-dashboards.Dashboard ee.api.dashboard_collaborator passed-as-class(cast) 1
-dashboards.Dashboard ee.api.subscription instance-many(manager) 2
-dashboards.Dashboard ee.api.subscription instance-single 1
-dashboards.Dashboard ee.hogai.context.entity_search.context in-collection 1
-dashboards.Dashboard ee.hogai.eval.ci.max_tools.eval_upsert_dashboard instance-many(filter) 1
-dashboards.Dashboard ee.hogai.eval.ci.max_tools.eval_upsert_dashboard write(acreate) 1
-dashboards.Dashboard ee.hogai.tools.read_data.tool instance-many(aget) 1
-dashboards.Dashboard ee.hogai.tools.upsert_dashboard.tool instance-many(aget) 1
-dashboards.Dashboard ee.hogai.tools.upsert_dashboard.tool write(create) 1
-dashboards.Dashboard posthog.api.search in-collection 1
-dashboards.Dashboard posthog.api.search instance-many(none) 1
-dashboards.Dashboard posthog.api.sharing instance-single 1
-dashboards.Dashboard posthog.api.sharing passed-as-class(cast) 1
-dashboards.Dashboard posthog.api.sharing_publish_gate isinstance 1
-dashboards.Dashboard posthog.api.welcome instance-many(filter) 1
-dashboards.Dashboard posthog.helpers.dashboard_templates write(create) 2
-dashboards.Dashboard posthog.middleware instance-many(filter) 1
-dashboards.Dashboard posthog.models.activity_logging.activity_log isinstance 1
-dashboards.Dashboard posthog.models.file_system.unfiled_file_saver in-collection 1
-dashboards.Dashboard posthog.models.product_intent.product_intent instance-many(filter) 1
-dashboards.Dashboard posthog.models.resource_transfer.visitors.dashboard other(Return) 1
-dashboards.Dashboard posthog.models.team.team write(create) 1
-dashboards.Dashboard posthog.rbac.migrations.rbac_dashboard_migration instance-many(filter) 1
-dashboards.Dashboard posthog.tasks.usage_report instance-many(order_by) 4
-dashboards.Dashboard posthog.temporal.usage_report.queries instance-many(order_by) 4
-dashboards.Dashboard posthog.user_permissions instance-many(filter) 2
-dashboards.Dashboard products.demo.backend.logic.legacy.app_data_generator write(create) 1
-dashboards.Dashboard products.demo.backend.logic.legacy.insight_variables_data_generator write(create) 1
-dashboards.Dashboard products.demo.backend.logic.legacy.revenue_data_generator write(create) 1
-dashboards.Dashboard products.demo.backend.logic.legacy.web_data_generator write(create) 1
-dashboards.Dashboard products.demo.backend.logic.products.hedgebox.matrix write(create) 3
-dashboards.Dashboard products.feature_flags.backend.api.feature_flag drf-field-queryset 1
-dashboards.Dashboard products.feature_flags.backend.api.feature_flag instance-single 1
-dashboards.Dashboard products.feature_flags.backend.api.feature_flag write(create) 1
-dashboards.Dashboard products.feature_flags.backend.management.commands.delete_feature_flag_usage_insights instance-many(filter) 1
-dashboards.Dashboard products.posthog_ai.eval_harness.data_setup write(create) 1
-dashboards.Dashboard products.product_analytics.backend.presentation.insight drf-field-queryset 1
-dashboards.Dashboard products.product_analytics.backend.presentation.insight instance-many(filter) 3
-dashboards.Dashboard products.pulse.backend.api.brief instance-many(filter) 1
-dashboards.Dashboard products.pulse.backend.generation.persist in-collection 1
-dashboards.Dashboard products.pulse.backend.generation.persist other(BinOp) 1
-dashboards.Dashboard products.pulse.backend.sources.anchored_dashboards instance-many(filter) 2
-dashboards.Dashboard products.reminders.backend.constants in-collection 1
-dashboards.Dashboard products.signals.backend.scout_harness.profile.builders instance-many(order_by) 1
-dashboards.Dashboard products.slack_app.backend.slack_link_unfurl instance-single 1
-dashboards.DashboardTile ee.api.subscription instance-many(manager) 2
-dashboards.DashboardTile ee.hogai.eval.ci.max_tools.eval_upsert_dashboard write(acreate) 1
-dashboards.DashboardTile ee.hogai.tools.upsert_dashboard.tool construct 1
-dashboards.DashboardTile ee.hogai.tools.upsert_dashboard.tool instance-many(select_related) 2
-dashboards.DashboardTile ee.hogai.tools.upsert_dashboard.tool other(Attribute:sort_tiles_by_layout) 1
-dashboards.DashboardTile ee.hogai.tools.upsert_dashboard.tool write(bulk_create) 1
-dashboards.DashboardTile ee.hogai.tools.upsert_dashboard.tool write(create) 1
-dashboards.DashboardTile ee.hogai.tools.upsert_dashboard.tool write(update) 2
-dashboards.DashboardTile posthog.caching.calculate_results isinstance 1
-dashboards.DashboardTile posthog.helpers.dashboard_templates write(create) 5
-dashboards.DashboardTile posthog.models.activity_logging.activity_log isinstance 1
-dashboards.DashboardTile posthog.models.resource_transfer.visitors.dashboard_tile other(Return) 1
-dashboards.DashboardTile products.demo.backend.logic.legacy.app_data_generator write(create) 1
-dashboards.DashboardTile products.demo.backend.logic.legacy.insight_variables_data_generator write(create) 5
-dashboards.DashboardTile products.demo.backend.logic.legacy.revenue_data_generator write(create) 1
-dashboards.DashboardTile products.demo.backend.logic.legacy.web_data_generator write(create) 1
-dashboards.DashboardTile products.demo.backend.logic.products.hedgebox.matrix write(create) 10
-dashboards.DashboardTile products.exports.backend.tasks.image_exporter instance-single 1
-dashboards.DashboardTile products.feature_flags.backend.management.commands.delete_feature_flag_usage_insights instance-many(filter) 1
-dashboards.DashboardTile products.feature_flags.backend.management.commands.delete_feature_flag_usage_insights write(update) 1
-dashboards.DashboardTile products.posthog_ai.eval_harness.data_setup write(create) 3
-dashboards.DashboardTile products.product_analytics.backend.admin write(update) 1
-dashboards.DashboardTile products.product_analytics.backend.migrations.0004_delete_revenue_analytics_insights get_model 1
-dashboards.DashboardTile products.product_analytics.backend.presentation.insight drf-model-serializer 1
-dashboards.DashboardTile products.product_analytics.backend.presentation.insight instance-many(all) 1
-dashboards.DashboardTile products.product_analytics.backend.presentation.insight instance-many(exclude) 1
-dashboards.DashboardTile products.product_analytics.backend.presentation.insight instance-many(filter) 2
-dashboards.DashboardTile products.product_analytics.backend.presentation.insight instance-many(select_related) 1
-dashboards.DashboardTile products.product_analytics.backend.presentation.insight instance-single 1
-dashboards.DashboardTile products.product_analytics.backend.presentation.insight other(Attribute:dashboard_queryset) 1
-dashboards.DashboardTile products.product_analytics.backend.presentation.insight prefetch 2
-dashboards.DashboardTile products.product_analytics.backend.presentation.insight write(create) 1
-dashboards.DashboardTile products.product_analytics.backend.presentation.insight write(get_or_create) 1
-dashboards.DashboardTile products.product_analytics.backend.presentation.insight write(update) 4
-dashboards.Text posthog.helpers.dashboard_templates write(create) 1
-dashboards.Text posthog.models.resource_transfer.visitors.text other(Return) 1
product_analytics.Insight ee.api.subscription instance-many(filter) 2
product_analytics.Insight ee.api.subscription instance-many(manager) 2
product_analytics.Insight ee.hogai.artifacts.handlers.visualization instance-many(filter) 1
diff --git a/products/product_analytics/backend/presentation/insight.py b/products/product_analytics/backend/presentation/insight.py
index 1b0f71b6bdfe..674446b041d3 100644
--- a/products/product_analytics/backend/presentation/insight.py
+++ b/products/product_analytics/backend/presentation/insight.py
@@ -6,8 +6,9 @@ from functools import lru_cache
from typing import Any, Union, cast
from django.conf import settings
+from django.core.exceptions import ObjectDoesNotExist
from django.db import transaction
-from django.db.models import Count, Exists, F, Max, OuterRef, Prefetch, QuerySet, Subquery
+from django.db.models import Count, F, Max, OuterRef, QuerySet, Subquery
from django.db.models.query_utils import Q
from django.http import HttpResponse
from django.utils.text import slugify
@@ -25,7 +26,7 @@ from pydantic import (
RootModel,
ValidationError as PydanticValidationError,
)
-from rest_framework import relations, request, serializers, status, viewsets
+from rest_framework import request, serializers, status, viewsets
from rest_framework.exceptions import APIException, ParseError, PermissionDenied, ValidationError
from rest_framework.parsers import JSONParser
from rest_framework.renderers import BaseRenderer
@@ -48,14 +49,9 @@ from posthog.api.monitoring import Feature, monitor
from posthog.api.openapi_parameters import make_filters_override_param, make_variables_override_param
from posthog.api.query_coalescer import QueryCoalescingMixin
from posthog.api.routing import TeamAndOrgViewSetMixin
-from posthog.api.scoped_related_fields import TeamScopedPrimaryKeyRelatedField
from posthog.api.services.query import process_query_dict, process_query_model
from posthog.api.shared import SearchMatchTypeSerializerMixin, UserBasicSerializer
-from posthog.api.sharing_publish_gate import (
- blocked_access_for_user,
- check_can_add_insight_to_shared_dashboard,
- is_publicly_shared,
-)
+from posthog.api.sharing_publish_gate import blocked_access_for_user, is_publicly_shared
from posthog.api.tagged_item import TaggedItemSerializerMixin, TaggedItemViewSetMixin
from posthog.api.utils import action, format_paginated_url
from posthog.auth import (
@@ -143,15 +139,32 @@ from posthog.utils import (
variables_override_requested_by_client,
)
-from products.alerts.backend.facade.api import serialize_insight_alerts
-from products.alerts.backend.facade.models import AlertConfiguration
-from products.cohorts.backend.facade.models import Cohort
+from products.alerts.backend.facade.api import delete_insight_alerts, insight_alerts_prefetch, serialize_insight_alerts
from products.dashboards.backend.facade.access import (
DashboardAccessMethod,
dashboard_access_method,
record_dashboard_cache_outcome,
)
-from products.dashboards.backend.facade.models import Dashboard, DashboardTile
+from products.dashboards.backend.facade.api import (
+ CannotAddToDashboard,
+ CannotRemoveFromDashboard,
+ DashboardNotFound,
+ DashboardTileBasicSerializer,
+ InsightTilePlacement,
+ active_tile_count,
+ hide_tiles_for_insights,
+ insight_has_listed_tile,
+ insight_ids_on_dashboard,
+ plan_insight_tile_placement,
+ restore_tiles_for_insights,
+ tile_for_insight_on_dashboard,
+ tile_for_render,
+ tile_ids_prefetch,
+ tile_permissions_prefetch,
+ unknown_dashboard_ids,
+ update_insight_dashboard_membership,
+)
+from products.dashboards.backend.facade.enums import PrivilegeLevel, RestrictionLevel
from products.product_analytics.backend.facade.api import map_stale_to_latest, plan_test_account_filter_update
from products.product_analytics.backend.facade.models import Insight, InsightVariable, InsightViewed
from products.product_analytics.backend.presentation.insight_metadata import (
@@ -319,28 +332,20 @@ class QuerySchemaParser(JSONParser):
return data
-class _DashboardsFromTilesManyField(serializers.ManyRelatedField):
- def get_attribute(self, instance: Insight) -> list[int]:
- return [tile.dashboard_id for tile in instance.dashboard_tiles.all()]
-
- def to_representation(self, iterable: Sequence[Any]) -> list[Any]:
- return list(iterable)
+class DashboardIdsField(serializers.ListField):
+ """The dashboard ids an insight sits on.
+ Written as a plain id list, read back off the prefetched tiles rather than the `dashboards`
+ m2m, so serializing a page of insights costs no extra query per insight.
+ """
-class TeamScopedDashboardsField(TeamScopedPrimaryKeyRelatedField):
- @classmethod
- def many_init(cls, *args, **kwargs):
- list_kwargs: dict[str, Any] = {"child_relation": cls(*args, **kwargs)}
- for key in kwargs:
- if key in relations.MANY_RELATION_KWARGS:
- list_kwargs[key] = kwargs[key]
- return _DashboardsFromTilesManyField(**list_kwargs)
+ child = serializers.IntegerField()
+ def get_attribute(self, instance: Insight) -> list[int]:
+ return [tile.dashboard_id for tile in instance.dashboard_tiles.all()]
-class DashboardTileBasicSerializer(serializers.ModelSerializer):
- class Meta:
- model = DashboardTile
- fields = ["id", "dashboard_id", "deleted"]
+ def to_representation(self, data: Sequence[Any]) -> list[Any]:
+ return list(data)
INCLUDE_DASHBOARDS_PARAM = "include_dashboards"
@@ -620,7 +625,7 @@ class InsightSerializer(InsightBasicSerializer):
effective_privilege_level = serializers.SerializerMethodField()
timezone = serializers.SerializerMethodField(help_text="The timezone this chart is displayed in.")
last_viewed_at = serializers.SerializerMethodField(read_only=True)
- dashboards = TeamScopedDashboardsField( # type: ignore[assignment]
+ dashboards = DashboardIdsField( # type: ignore[assignment]
help_text="""
DEPRECATED. Will be removed in a future release. Use dashboard_tiles instead.
A dashboard ID for each of the dashboards that this insight is displayed on.
@@ -628,9 +633,7 @@ class InsightSerializer(InsightBasicSerializer):
is passed. Once opt-in enforcement is enabled, API-token callers (personal API keys, OAuth)
must opt in the same way. Do not rely on it being present.
""",
- many=True,
required=False,
- queryset=Dashboard.objects.all(),
)
dashboard_tiles = DashboardTileBasicSerializer(
many=True,
@@ -720,27 +723,37 @@ class InsightSerializer(InsightBasicSerializer):
):
raise PermissionDenied("Creating or updating insights with legacy filters is not available for this user.")
- new_dashboards = attrs.get("dashboards")
- if new_dashboards is not None:
+ new_dashboard_ids = attrs.get("dashboards")
+ if new_dashboard_ids is not None:
team = self.context["get_team"]()
existing_dashboard_ids: set[int] = set()
if self.instance is not None:
existing_dashboard_ids = set(
self.instance.dashboard_tiles.exclude(deleted=True).values_list("dashboard_id", flat=True)
)
- for dashboard in new_dashboards:
- if dashboard.id in existing_dashboard_ids:
+ for dashboard_id in new_dashboard_ids:
+ if dashboard_id in existing_dashboard_ids:
continue
- current_tiles = DashboardTile.objects.filter(dashboard_id=dashboard.id).exclude(deleted=True).count()
check_count_limit(
team=team,
key=LimitKey.MAX_INSIGHTS_PER_DASHBOARD,
- current_count=current_tiles,
+ current_count=active_tile_count(dashboard_id),
user=self.context["request"].user,
)
return super().validate(attrs)
+ def validate_dashboards(self, value: list[int]) -> list[int]:
+ # Fails safe like the team-scoped related field this replaced: without a team in context,
+ # no id resolves.
+ team_id = self.context.get("team_id")
+ unknown = list(value) if not team_id else unknown_dashboard_ids(value, team_id=team_id)
+ if unknown:
+ raise serializers.ValidationError(
+ f"Dashboard not found: {', '.join(str(dashboard_id) for dashboard_id in unknown)}"
+ )
+ return value
+
def validate_query(self, value: dict[str, Any] | None) -> dict[str, Any] | None:
"""Auto-wrap bare query sources in the wrapper node the UI renders.
@@ -772,33 +785,28 @@ class InsightSerializer(InsightBasicSerializer):
team_id = self.context["team_id"]
created_by = validated_data.pop("created_by", request.user)
- dashboards = validated_data.pop("dashboards", None)
+ dashboard_ids = validated_data.pop("dashboards", None)
# Validate dashboard access before creating anything: create() runs in autocommit,
# so raising mid-way would otherwise leave an orphaned insight (and emit user actions
# for tiles that never persist on multi-dashboard requests).
- target_dashboards: list[Dashboard] = []
- if dashboards is not None:
+ placement: InsightTilePlacement | None = None
+ if dashboard_ids is not None:
# Per-dashboard limit (analytics.max_insights_per_dashboard) is enforced
# in validate(); see InsightSerializer.validate above.
- # nosemgrep: idor-lookup-without-team
- target_dashboards = list(Dashboard.objects.filter(id__in=[d.id for d in dashboards]))
- for dashboard in target_dashboards:
- # Mirror the update path: adding a tile is an edit of the dashboard, so a
- # restricted dashboard the user can't edit must not be writable on create either.
- if (
- self.user_permissions.dashboard(dashboard).effective_privilege_level
- != Dashboard.PrivilegeLevel.CAN_EDIT
- ):
- raise PermissionDenied(f"You don't have permission to add insights to dashboard: {dashboard.id}")
-
- if dashboard.team_id != team_id:
- raise serializers.ValidationError("Dashboard not found")
-
- # The dashboard's public link must not expose a query the editor can't run.
- check_can_add_insight_to_shared_dashboard(
- request.user, dashboard, validated_data.get("query"), self.user_access_control
+ try:
+ placement = plan_insight_tile_placement(
+ dashboard_ids=dashboard_ids,
+ team_id=team_id,
+ query=validated_data.get("query"),
+ user=request.user,
+ user_permissions=self.user_permissions,
+ user_access_control=self.user_access_control,
)
+ except CannotAddToDashboard as error:
+ raise PermissionDenied(f"You don't have permission to add insights to dashboard: {error.dashboard_id}")
+ except DashboardNotFound:
+ raise serializers.ValidationError("Dashboard not found")
# Counts the field being accepted as write input (even an empty list), after
# permission checks so rejected requests don't inflate the metric.
@@ -813,21 +821,19 @@ class InsightSerializer(InsightBasicSerializer):
InsightViewed.objects.create(team_id=team_id, user=request.user, insight=insight, last_viewed_at=now())
- for dashboard in target_dashboards:
- DashboardTile.objects.create(
- insight=insight, dashboard=dashboard, team_id=dashboard.team_id, last_refresh=now()
- )
- report_user_action(
- self.context["request"].user,
- "dashboard tile added",
- {
- "tile_type": "insight",
- "insight_type": get_insight_type(insight),
- "dashboard_id": dashboard.id,
- },
- team=insight.team,
- request=self.context["request"],
- )
+ if placement is not None:
+ for dashboard in placement.create_tiles(insight):
+ report_user_action(
+ self.context["request"].user,
+ "dashboard tile added",
+ {
+ "tile_type": "insight",
+ "insight_type": get_insight_type(insight),
+ "dashboard_id": dashboard.id,
+ },
+ team=insight.team,
+ request=self.context["request"],
+ )
# Manual tag creation since this create method doesn't call super()
self._attempt_set_tags(tags, insight)
@@ -901,13 +907,13 @@ class InsightSerializer(InsightBasicSerializer):
)
if validated_data.get("deleted", False):
- DashboardTile.objects_including_soft_deleted.filter(insight__id=instance.id).update(deleted=True)
+ hide_tiles_for_insights([instance.id])
for alert in instance.alertconfiguration_set.all():
alert.delete()
else:
- dashboards = validated_data.pop("dashboards", None)
- if dashboards is not None:
- self._update_insight_dashboards(dashboards, instance)
+ dashboard_ids = validated_data.pop("dashboards", None)
+ if dashboard_ids is not None:
+ self._update_insight_dashboards(dashboard_ids, instance)
updated_insight = super().update(instance, validated_data)
# Delete linked alerts only when the insight can no longer carry any alert. A switch between
@@ -980,93 +986,64 @@ class InsightSerializer(InsightBasicSerializer):
return []
- def _update_insight_dashboards(self, dashboards: list[Dashboard], instance: Insight) -> None:
+ def _update_insight_dashboards(self, dashboard_ids: list[int], instance: Insight) -> None:
# Counts the field being accepted as write input — before the no-op early return, so
# integrations that round-trip an unchanged dashboards list still register as writers.
_record_deprecated_dashboards_field_used(self.context, usage="write")
- old_dashboard_ids = [tile.dashboard_id for tile in instance.dashboard_tiles.all()]
- new_dashboard_ids = [d.id for d in dashboards if not d.deleted]
-
- if sorted(old_dashboard_ids) == sorted(new_dashboard_ids):
- return
-
- ids_to_add = [id for id in new_dashboard_ids if id not in old_dashboard_ids]
- ids_to_remove = [id for id in old_dashboard_ids if id not in new_dashboard_ids]
- # nosemgrep: idor-lookup-without-team (team check after lookup)
- candidate_dashboards = Dashboard.objects.filter(id__in=ids_to_add)
- dashboard: Dashboard
- for dashboard in candidate_dashboards:
- # does this user have permission on dashboards to add... if they are restricted
- # it will mean this dashboard becomes restricted because of the patch
- if (
- self.user_permissions.dashboard(dashboard).effective_privilege_level
- != Dashboard.PrivilegeLevel.CAN_EDIT
- ):
- raise PermissionDenied(f"You don't have permission to add insights to dashboard: {dashboard.id}")
-
- if dashboard.team != instance.team:
- raise serializers.ValidationError("Dashboard not found")
-
- # The dashboard's public link must not expose a query the editor can't run.
- check_can_add_insight_to_shared_dashboard(
- self.context["request"].user, dashboard, instance.query, self.user_access_control
+ try:
+ change = update_insight_dashboard_membership(
+ insight=instance,
+ dashboard_ids=dashboard_ids,
+ user=self.context["request"].user,
+ user_permissions=self.user_permissions,
+ user_access_control=self.user_access_control,
)
+ except CannotAddToDashboard as error:
+ raise PermissionDenied(f"You don't have permission to add insights to dashboard: {error.dashboard_id}")
+ except CannotRemoveFromDashboard as error:
+ raise PermissionDenied(f"You don't have permission to remove insights from dashboard: {error.dashboard_id}")
+ except DashboardNotFound:
+ raise serializers.ValidationError("Dashboard not found")
+
+ if change is None:
+ return
- tile, _ = DashboardTile.objects_including_soft_deleted.get_or_create(insight=instance, dashboard=dashboard)
-
- if tile.deleted:
- tile.deleted = False
- tile.save()
-
+ for dashboard_id in change.added_dashboard_ids:
report_user_action(
self.context["request"].user,
"dashboard tile added",
{
"tile_type": "insight",
"insight_type": get_insight_type(instance),
- "dashboard_id": dashboard.id,
+ "dashboard_id": dashboard_id,
},
team=instance.team,
request=self.context["request"],
)
- if ids_to_remove:
- # Check permission before removing insight from dashboards
- # nosemgrep: idor-lookup-without-team (team check after lookup)
- dashboards_to_remove = Dashboard.objects.filter(id__in=ids_to_remove)
- for dashboard in dashboards_to_remove:
- if (
- self.user_permissions.dashboard(dashboard).effective_privilege_level
- != Dashboard.PrivilegeLevel.CAN_EDIT
- ):
- raise PermissionDenied(
- f"You don't have permission to remove insights from dashboard: {dashboard.id}"
- )
-
- # Capture the still-active tiles before soft-deleting so we report one
- # "dashboard tile removed" per tile that is actually removed.
- tiles_to_remove = list(DashboardTile.objects.filter(dashboard_id__in=ids_to_remove, insight=instance))
- DashboardTile.objects.filter(dashboard_id__in=ids_to_remove, insight=instance).update(deleted=True)
-
- for tile in tiles_to_remove:
- report_user_action(
- self.context["request"].user,
- "dashboard tile removed",
- {
- "tile_type": "insight",
- "insight_type": get_insight_type(instance),
- "dashboard_id": tile.dashboard_id,
- },
- team=instance.team,
- request=self.context["request"],
- )
+ for dashboard_id in change.removed_dashboard_ids:
+ report_user_action(
+ self.context["request"].user,
+ "dashboard tile removed",
+ {
+ "tile_type": "insight",
+ "insight_type": get_insight_type(instance),
+ "dashboard_id": dashboard_id,
+ },
+ team=instance.team,
+ request=self.context["request"],
+ )
# Dashboard membership is mutated through separate querysets above, so the instance's
# prefetched relation no longer reflects what was persisted. The response serializer must
# reload it because session callers now derive membership exclusively from dashboard_tiles.
getattr(instance, "_prefetched_objects_cache", {}).pop("dashboard_tiles", None)
- self.context["after_dashboard_changes"] = [describe_change(d) for d in dashboards if not d.deleted]
+ # Same shape describe_change() renders a dashboard as, so this lines up with the "before"
+ # side of the synthetic dashboards change further up.
+ self.context["after_dashboard_changes"] = [
+ {"id": dashboard.id, "name": dashboard.name} for dashboard in change.dashboards
+ ]
@extend_schema_field(OpenApiTypes.ANY)
def get_result(self, insight: Insight):
@@ -1159,7 +1136,7 @@ class InsightSerializer(InsightBasicSerializer):
@extend_schema_field(InsightFilterOverrideContext) # type: ignore[arg-type]
def get_filter_override_context(self, insight: Insight) -> dict[str, object] | None:
- dashboard: Dashboard | None = self.context.get("dashboard")
+ dashboard: Any = self.context.get("dashboard")
request: Request | None = self.context.get("request")
if request is None:
return None
@@ -1181,14 +1158,14 @@ class InsightSerializer(InsightBasicSerializer):
resolved_layers = resolve_filter_layers_by_priority(dashboard_filters, tile_filters_override)
return {key: value or None for key, value in resolved_layers.items()}
- def get_effective_restriction_level(self, insight: Insight) -> Dashboard.RestrictionLevel:
+ def get_effective_restriction_level(self, insight: Insight) -> RestrictionLevel:
if self.context.get("is_shared"):
- return Dashboard.RestrictionLevel.ONLY_COLLABORATORS_CAN_EDIT
+ return RestrictionLevel.ONLY_COLLABORATORS_CAN_EDIT
return self.user_permissions.insight(insight).effective_restriction_level
- def get_effective_privilege_level(self, insight: Insight) -> Dashboard.PrivilegeLevel:
+ def get_effective_privilege_level(self, insight: Insight) -> PrivilegeLevel:
if self.context.get("is_shared"):
- return Dashboard.PrivilegeLevel.CAN_VIEW
+ return PrivilegeLevel.CAN_VIEW
return self.user_permissions.insight(insight).effective_privilege_level
def to_representation(self, instance: Insight):
@@ -1218,7 +1195,7 @@ class InsightSerializer(InsightBasicSerializer):
described_dashboard["id"] for described_dashboard in self.context["after_dashboard_changes"]
]
- dashboard: Dashboard | None = self.context.get("dashboard")
+ dashboard: Any = self.context.get("dashboard")
request: Request | None = self.context.get("request")
is_shared = self.context.get("is_shared", False)
dashboard_filters_override = (
@@ -1298,7 +1275,7 @@ class InsightSerializer(InsightBasicSerializer):
def insight_result(self, insight: Insight) -> InsightResult:
from posthog.caching.calculate_results import calculate_for_query_based_insight
- dashboard: Dashboard | None = self.context.get("dashboard")
+ dashboard: Any = self.context.get("dashboard")
# Check if we have an expected cache key from the image exporter
export_cache_keys: dict[int, str] | None = self.context.get("export_cache_keys")
@@ -1452,7 +1429,7 @@ class InsightSerializer(InsightBasicSerializer):
def _degraded_insight_result(
self,
insight: Insight,
- dashboard: Dashboard | None,
+ dashboard: Any,
*,
error_message: str,
error_code: str | None,
@@ -1487,17 +1464,15 @@ class InsightSerializer(InsightBasicSerializer):
)
@lru_cache(maxsize=1) # noqa: B019 - short-lived serializer, one insight/tile combo
- def dashboard_tile_from_context(self, insight: Insight, dashboard: Dashboard | None) -> DashboardTile | None:
- dashboard_tile: DashboardTile | None = self.context.get("dashboard_tile", None)
+ def dashboard_tile_from_context(self, insight: Insight, dashboard: Any) -> Any:
+ dashboard_tile: Any = self.context.get("dashboard_tile", None)
if dashboard_tile and dashboard_tile.deleted:
self.context.update({"dashboard_tile": None})
dashboard_tile = None
if not dashboard_tile and dashboard:
- dashboard_tile = DashboardTile.dashboard_queryset(
- DashboardTile.objects.filter(insight=insight, dashboard=dashboard)
- ).first()
+ dashboard_tile = tile_for_render(insight=insight, dashboard=dashboard)
return dashboard_tile
@@ -1885,27 +1860,11 @@ class InsightViewSet(
is_basic = self._is_basic_request()
if is_basic:
- queryset = queryset.prefetch_related(
- Prefetch(
- "dashboard_tiles",
- queryset=DashboardTile.objects.only("id", "dashboard_id", "deleted", "insight_id"),
- ),
- )
+ queryset = queryset.prefetch_related(tile_ids_prefetch())
else:
queryset = queryset.prefetch_related(
- Prefetch(
- "dashboard_tiles",
- queryset=DashboardTile.objects.select_related("dashboard__team__organization"),
- ),
- Prefetch(
- "alertconfiguration_set",
- # AlertSerializer emits threshold and subscribed_users per alert; without these,
- # every alert in the list costs two extra queries
- queryset=AlertConfiguration.objects.select_related("created_by", "threshold").prefetch_related(
- "subscribed_users"
- ),
- to_attr="_prefetched_alerts",
- ),
+ tile_permissions_prefetch(),
+ insight_alerts_prefetch(to_attr="_prefetched_alerts"),
)
# Add access level filtering for list actions if not sharing access token
@@ -2085,10 +2044,7 @@ class InsightViewSet(
for key in filters:
if key == "saved":
if str_to_bool(request.GET["saved"]):
- visible_tile_for_insight = DashboardTile.objects.filter(insight=OuterRef("pk")).exclude(
- dashboard__creation_mode="unlisted"
- )
- queryset = queryset.filter(Q(saved=True) | Exists(visible_tile_for_insight))
+ queryset = queryset.filter(Q(saved=True) | insight_has_listed_tile())
else:
queryset = queryset.filter(Q(saved=False))
elif key == "feature_flag":
@@ -2173,11 +2129,7 @@ class InsightViewSet(
dashboards_ids = json.loads(dashboards_filter)
for dashboard_id in dashboards_ids:
# filter by dashboards one at a time so the filter is AND not OR
- queryset = queryset.filter(
- id__in=DashboardTile.objects.filter(dashboard__id=dashboard_id)
- .values_list("insight__id", flat=True)
- .all()
- )
+ queryset = queryset.filter(id__in=insight_ids_on_dashboard(dashboard_id))
elif key == "tags":
tags_filter = request.GET["tags"]
if tags_filter:
@@ -2248,14 +2200,10 @@ When set, the specified dashboard's filters and date range override will be appl
instance = self.get_object()
serializer_context = self.get_serializer_context()
- dashboard_tile: DashboardTile | None = None
+ dashboard_tile: Any = None
dashboard_id = request.query_params.get("from_dashboard", None)
if dashboard_id is not None:
- dashboard_tile = (
- DashboardTile.objects.filter(dashboard__id=dashboard_id, insight__id=instance.id)
- .select_related("dashboard")
- .first()
- )
+ dashboard_tile = tile_for_insight_on_dashboard(insight_id=instance.id, dashboard_id=dashboard_id)
if dashboard_tile is not None:
authenticator = request.successful_authenticator
@@ -2500,7 +2448,10 @@ When set, the specified dashboard's filters and date range override will be appl
raise ValidationError(str(e), getattr(e, "code_name", None))
except UserAccessControlError as e:
raise ValidationError(str(e))
- except Cohort.DoesNotExist as e:
+ except ObjectDoesNotExist as e:
+ # The legacy filter path resolves cohort and action ids while building the query, and a
+ # dangling id surfaces as that model's DoesNotExist. The request is what is wrong, so it
+ # is a 400 rather than a 500.
raise ValidationError(str(e))
filter = Filter(request=request, team=self.team)
@@ -2669,11 +2620,9 @@ When set, the specified dashboard's filters and date range override will be appl
Insight.objects_including_soft_deleted.filter(
id__in=insight_ids, team__project_id=self.team.project_id
).update(deleted=True, last_modified_at=now(), last_modified_by=current_user)
- # Match InsightSerializer.update: hide the insights' tiles and remove linked alerts. Alerts are
- # deleted one at a time (not a queryset .delete()) so ModelActivityMixin.delete logs each removal.
- DashboardTile.objects_including_soft_deleted.filter(insight_id__in=insight_ids).update(deleted=True)
- for alert in AlertConfiguration.objects.filter(insight_id__in=insight_ids):
- alert.delete()
+ # Match InsightSerializer.update: hide the insights' tiles and remove linked alerts.
+ hide_tiles_for_insights(insight_ids)
+ delete_insight_alerts(insight_ids)
activity_log_entries: list[LogActivityEntry] = []
for insight in insights:
@@ -2724,23 +2673,7 @@ When set, the specified dashboard's filters and date range override will be appl
Insight.objects_including_soft_deleted.filter(
id__in=insight_ids, team__project_id=self.team.project_id
).update(deleted=False, last_modified_at=now(), last_modified_by=current_user)
- # Re-activate tiles linking these insights to live dashboards, but only ones the requester may
- # edit — mirrors the per-dashboard CAN_EDIT check in InsightSerializer._update_insight_dashboards
- # so a restore can't force an insight back onto a dashboard the user can only view. Tiles removed
- # before the bulk delete may also reappear; acceptable for the immediate-undo case this backs.
- candidate_tiles = DashboardTile.objects_including_soft_deleted.filter(
- insight_id__in=insight_ids, deleted=True, dashboard__deleted=False
- ).select_related("dashboard")
- restorable_tile_ids = [
- tile.id
- for tile in candidate_tiles
- if self.user_permissions.dashboard(tile.dashboard).effective_privilege_level
- == Dashboard.PrivilegeLevel.CAN_EDIT
- ]
- if restorable_tile_ids:
- DashboardTile.objects_including_soft_deleted.filter(id__in=restorable_tile_ids).update(
- deleted=False
- )
+ restore_tiles_for_insights(insight_ids, user_permissions=self.user_permissions)
activity_log_entries: list[LogActivityEntry] = []
for insight in insights:
diff --git a/products/product_analytics/backend/presentation/insight_ee.py b/products/product_analytics/backend/presentation/insight_ee.py
index 318033163290..394b158b1cb8 100644
--- a/products/product_analytics/backend/presentation/insight_ee.py
+++ b/products/product_analytics/backend/presentation/insight_ee.py
@@ -3,7 +3,7 @@
from rest_framework.permissions import SAFE_METHODS, BasePermission
from rest_framework.request import Request
-from products.dashboards.backend.facade.models import Dashboard
+from products.dashboards.backend.facade.enums import PrivilegeLevel
from products.product_analytics.backend.facade.models import Insight
from products.product_analytics.backend.presentation.insight import InsightViewSet
@@ -15,7 +15,7 @@ class CanEditInsight(BasePermission):
if request.method in SAFE_METHODS:
return True
- return view.user_permissions.insight(insight).effective_privilege_level == Dashboard.PrivilegeLevel.CAN_EDIT
+ return view.user_permissions.insight(insight).effective_privilege_level == PrivilegeLevel.CAN_EDIT
class EnterpriseInsightsViewSet(InsightViewSet):
diff --git a/products/product_analytics/backend/test/__init__.py b/products/product_analytics/backend/test/__init__.py
deleted file mode 100644
index e69de29bb2d1..000000000000
diff --git a/products/cohorts/backend/facade/__init__.py b/products/product_analytics/backend/tests/__init__.py
similarity index 100%
rename from products/cohorts/backend/facade/__init__.py
rename to products/product_analytics/backend/tests/__init__.py
diff --git a/products/product_analytics/backend/presentation/test/__init__.py b/products/product_analytics/backend/tests/api/__init__.py
similarity index 100%
rename from products/product_analytics/backend/presentation/test/__init__.py
rename to products/product_analytics/backend/tests/api/__init__.py
diff --git a/products/product_analytics/backend/presentation/test/__snapshots__/test_insight.ambr b/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambr
similarity index 98%
rename from products/product_analytics/backend/presentation/test/__snapshots__/test_insight.ambr
rename to products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambr
index 45bd24bfa19e..cb6350f2e098 100644
--- a/products/product_analytics/backend/presentation/test/__snapshots__/test_insight.ambr
+++ b/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambr
@@ -1560,28 +1560,7 @@
# ---
# name: TestInsight.test_listing_insights_does_not_nplus1.6
'''
- SELECT "posthog_dashboard"."id",
- "posthog_dashboard"."name",
- "posthog_dashboard"."description",
- "posthog_dashboard"."team_id",
- "posthog_dashboard"."pinned",
- "posthog_dashboard"."created_at",
- "posthog_dashboard"."created_by_id",
- "posthog_dashboard"."deleted",
- "posthog_dashboard"."last_accessed_at",
- "posthog_dashboard"."last_refresh",
- "posthog_dashboard"."filters",
- "posthog_dashboard"."variables",
- "posthog_dashboard"."breakdown_colors",
- "posthog_dashboard"."data_color_theme_id",
- "posthog_dashboard"."creation_mode",
- "posthog_dashboard"."restriction_level",
- "posthog_dashboard"."quick_filter_ids",
- "posthog_dashboard"."customization",
- "posthog_dashboard"."deprecated_tags",
- "posthog_dashboard"."tags",
- "posthog_dashboard"."share_token",
- "posthog_dashboard"."is_shared"
+ SELECT "posthog_dashboard"."id" AS "id"
FROM "posthog_dashboard"
INNER JOIN "posthog_team" ON ("posthog_dashboard"."team_id" = "posthog_team"."id")
WHERE (NOT ("posthog_dashboard"."deleted")
@@ -1592,8 +1571,11 @@
LIMIT 1)
OR ("posthog_team"."parent_team_id" IS NULL
AND "posthog_dashboard"."team_id" = 99999))
- AND "posthog_dashboard"."id" = 99999)
- LIMIT 21
+ AND "posthog_dashboard"."id" IN (1,
+ 2,
+ 3,
+ 4,
+ 5 /* ... */))
'''
# ---
# name: TestInsight.test_listing_insights_does_not_nplus1.7
diff --git a/products/product_analytics/backend/presentation/test/__snapshots__/test_insight_funnels.ambr b/products/product_analytics/backend/tests/api/__snapshots__/test_insight_funnels.ambr
similarity index 100%
rename from products/product_analytics/backend/presentation/test/__snapshots__/test_insight_funnels.ambr
rename to products/product_analytics/backend/tests/api/__snapshots__/test_insight_funnels.ambr
diff --git a/products/product_analytics/backend/presentation/test/test_deprecated_dashboards_field.py b/products/product_analytics/backend/tests/api/test_deprecated_dashboards_field.py
similarity index 97%
rename from products/product_analytics/backend/presentation/test/test_deprecated_dashboards_field.py
rename to products/product_analytics/backend/tests/api/test_deprecated_dashboards_field.py
index 02f4b19ff90e..92d52a8fb67c 100644
--- a/products/product_analytics/backend/presentation/test/test_deprecated_dashboards_field.py
+++ b/products/product_analytics/backend/tests/api/test_deprecated_dashboards_field.py
@@ -10,7 +10,8 @@ from posthog.auth import PersonalAPIKeyAuthentication, SessionAuthentication, Sh
from posthog.models.personal_api_key import PersonalAPIKey
from posthog.models.utils import generate_random_token_personal, hash_key_value
-from products.dashboards.backend.facade.models import Dashboard, DashboardTile
+from products.dashboards.backend.models.dashboard import Dashboard
+from products.dashboards.backend.models.dashboard_tile import DashboardTile
from products.product_analytics.backend.facade.models import Insight
from products.product_analytics.backend.presentation.insight import should_serve_deprecated_dashboards_field
diff --git a/products/product_analytics/backend/presentation/test/test_insight.py b/products/product_analytics/backend/tests/api/test_insight.py
similarity index 99%
rename from products/product_analytics/backend/presentation/test/test_insight.py
rename to products/product_analytics/backend/tests/api/test_insight.py
index 3fbddf46d624..4e9e76530d4a 100644
--- a/products/product_analytics/backend/presentation/test/test_insight.py
+++ b/products/product_analytics/backend/tests/api/test_insight.py
@@ -55,10 +55,11 @@ from posthog.models.project import Project
from posthog.test.db_context_capturing import capture_db_queries
from posthog.test.persons import create_person
-from products.alerts.backend.facade.models import AlertConfiguration, AlertSubscription, Threshold
-from products.cohorts.backend.facade.models import Cohort
+from products.alerts.backend.models.alert import AlertConfiguration, AlertSubscription, Threshold
+from products.cohorts.backend.models.cohort import Cohort
from products.dashboards.backend.facade.access import DashboardAccessMethod
-from products.dashboards.backend.facade.models import Dashboard, DashboardTile, Text
+from products.dashboards.backend.models.dashboard import Dashboard
+from products.dashboards.backend.models.dashboard_tile import DashboardTile, Text
from products.product_analytics.backend.facade.models import Insight, InsightVariable, InsightViewed
from ee.models.rbac.access_control import AccessControl
@@ -3378,6 +3379,12 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
expected_status=status.HTTP_400_BAD_REQUEST,
)
+ def test_cannot_create_insight_on_a_dashboard_that_does_not_exist(self) -> None:
+ self.dashboard_api.create_insight(
+ data={"name": "insight", "dashboards": [9_999_999]},
+ expected_status=status.HTTP_400_BAD_REQUEST,
+ )
+
@skip("is this not how things work?")
def test_cannot_create_insight_in_another_team(
self,
diff --git a/products/product_analytics/backend/presentation/test/test_insight_funnels.py b/products/product_analytics/backend/tests/api/test_insight_funnels.py
similarity index 100%
rename from products/product_analytics/backend/presentation/test/test_insight_funnels.py
rename to products/product_analytics/backend/tests/api/test_insight_funnels.py
diff --git a/products/product_analytics/backend/presentation/test/test_insight_metadata.py b/products/product_analytics/backend/tests/api/test_insight_metadata.py
similarity index 100%
rename from products/product_analytics/backend/presentation/test/test_insight_metadata.py
rename to products/product_analytics/backend/tests/api/test_insight_metadata.py
diff --git a/products/product_analytics/backend/presentation/test/test_insight_query.py b/products/product_analytics/backend/tests/api/test_insight_query.py
similarity index 100%
rename from products/product_analytics/backend/presentation/test/test_insight_query.py
rename to products/product_analytics/backend/tests/api/test_insight_query.py
diff --git a/products/product_analytics/backend/presentation/test/test_insight_variable.py b/products/product_analytics/backend/tests/api/test_insight_variable.py
similarity index 100%
rename from products/product_analytics/backend/presentation/test/test_insight_variable.py
rename to products/product_analytics/backend/tests/api/test_insight_variable.py
diff --git a/products/product_analytics/backend/presentation/test/test_paths_v2.py b/products/product_analytics/backend/tests/api/test_paths_v2.py
similarity index 100%
rename from products/product_analytics/backend/presentation/test/test_paths_v2.py
rename to products/product_analytics/backend/tests/api/test_paths_v2.py
diff --git a/products/product_analytics/backend/test/test_insight_activity_logging.py b/products/product_analytics/backend/tests/test_insight_activity_logging.py
similarity index 100%
rename from products/product_analytics/backend/test/test_insight_activity_logging.py
rename to products/product_analytics/backend/tests/test_insight_activity_logging.py
diff --git a/products/product_analytics/backend/test/test_insight_admin.py b/products/product_analytics/backend/tests/test_insight_admin.py
similarity index 100%
rename from products/product_analytics/backend/test/test_insight_admin.py
rename to products/product_analytics/backend/tests/test_insight_admin.py
diff --git a/products/product_analytics/turbo.json b/products/product_analytics/turbo.json
index d9ed4a52f28a..545458f55c59 100644
--- a/products/product_analytics/turbo.json
+++ b/products/product_analytics/turbo.json
@@ -5,7 +5,6 @@
"inputs": [
"backend/facade/**",
"backend/presentation/**",
- "!backend/presentation/test/**",
"backend/routes.py",
"backend/models/**",
"backend/migrations/**",
diff --git a/proto/README.md b/proto/README.md
index 383e42bc9bec..d3cdba328b2d 100644
--- a/proto/README.md
+++ b/proto/README.md
@@ -12,10 +12,12 @@ proto/
├── ingestion/ # Event ingestion
│ └── worker/v1/ # Consumer → worker streaming ingest transport
├── kafka_assigner/ # Kafka partition assignment
-└── personhog/ # Person data service
- ├── types/v1/
- ├── replica/v1/
- └── service/v1/
+├── personhog/ # Person data service
+│ ├── types/v1/
+│ ├── replica/v1/
+│ └── service/v1/
+└── prometheus/ # Prometheus remote write
+ └── v1/ # Remote write transport
```
## Consumers
@@ -26,6 +28,7 @@ proto/
| `ingestion/` | `rust/ingestion-worker-proto` (auto via tonic) | — | `nodejs/src/common/generated/ingestion-worker` (checked in) |
| `personhog/` | `rust/personhog-proto` (auto via tonic) | `posthog/personhog_client/proto/generated/` (checked in) | `nodejs/src/common/generated/personhog` (checked in) |
| `kafka_assigner/` | `rust/kafka-assigner-proto` (auto via tonic) | — | — |
+| `prometheus/` | `rust/prometheus-rw-proto` (auto via tonic) | — | — |
## Updating protos
diff --git a/tools/hogli-commands/hogli_commands/product/isolation.py b/tools/hogli-commands/hogli_commands/product/isolation.py
index b311a61dd8a0..672e318b4013 100644
--- a/tools/hogli-commands/hogli_commands/product/isolation.py
+++ b/tools/hogli-commands/hogli_commands/product/isolation.py
@@ -506,13 +506,6 @@ CARVE_OUTS: frozenset[tuple[str, str]] = frozenset(
# products/architecture.md § Wiring couplings.
MODEL_CROSSINGS: frozenset[tuple[str, str]] = frozenset(
{
- ("alerts", "AlertConfiguration"),
- ("alerts", "AlertSubscription"),
- ("alerts", "Threshold"),
- ("cohorts", "Cohort"),
- ("dashboards", "Dashboard"),
- ("dashboards", "DashboardTile"),
- ("dashboards", "Text"),
("product_analytics", "Insight"),
("product_analytics", "InsightVariable"),
("product_analytics", "InsightViewed"),
diff --git a/tools/snob_backend_test_selection_shadow.py b/tools/snob_backend_test_selection_shadow.py
index 19d1c4f95e63..a40691f8a5d5 100755
--- a/tools/snob_backend_test_selection_shadow.py
+++ b/tools/snob_backend_test_selection_shadow.py
@@ -610,7 +610,7 @@ _POE_PREFIXES = (
"posthog/clickhouse/",
"posthog/queries/",
"ee/clickhouse/",
- "products/product_analytics/backend/presentation/test/",
+ "products/product_analytics/backend/tests/api/",
)
_CORE_IGNORED_PREFIXES = ("posthog/dags/", "common/hogvm/python/test/")