:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(devex): route system-tables test fixtures through product doors (#91460)
Julian Bez6f5be945b688
diff --git a/posthog/hogql/database/schema/test/test_system_tables.py b/posthog/hogql/database/schema/test/test_system_tables.pyindex 525646679171..b791d78c5ecd 100644--- a/posthog/hogql/database/schema/test/test_system_tables.py+++ b/posthog/hogql/database/schema/test/test_system_tables.py@@ -1,10 +1,8 @@import jsonimport uuid-from typing import TYPE_CHECKINGfrom posthog.test.base import BaseTest, NonAtomicBaseTest-from django.apps import appsfrom django.utils import timezonefrom parameterized import parameterized@@ -36,15 +34,42 @@ from products.alerts.backend.models.alert import AlertConfigurationfrom products.annotations.backend.models.annotation import Annotationfrom products.business_knowledge.backend.models import KnowledgeChunk, KnowledgeDocument, KnowledgeSourcefrom products.business_knowledge.backend.models.constants import SourceStatus, SourceType+from products.canvas.backend.models import Canvasfrom products.cdp.backend.models.hog_functions.hog_function import HogFunctionfrom products.cohorts.backend.models.calculation_history import CohortCalculationHistoryfrom products.cohorts.backend.models.cohort import Cohort-from products.conversations.backend.models import Ticket, TicketAssignment+from products.conversations.backend.models import EmailThread, EmailThreadAccountLink, Ticket, TicketAssignment+from products.customer_analytics.backend.facade.testing import (+ create_account,+ create_account_channel_summary,+ create_account_relationship,+ create_account_relationship_definition,+ create_custom_property_definition,+ create_custom_property_value,+ create_feature_request,+ create_feature_request_account_link,+ create_feature_request_evidence,+ create_feature_request_history,+ create_feature_request_product_area,+ create_feature_request_product_area_link,+ create_meeting,+)from products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTilefrom products.data_modeling.backend.facade.models import DataModelingJob, DataWarehouseSavedQueryfrom products.early_access_features.backend.models import EarlyAccessFeaturefrom products.endpoints.backend.facade.models import Endpoint, EndpointVersion+from products.error_tracking.backend.facade.testing import (+ create_assignment_rule,+ create_bypass_rule,+ create_issue,+ create_issue_assignment,+ create_issue_fingerprint,+ create_release,+ create_severity_rule,+ create_suppression_rule,+ create_symbol_set,+)from products.experiments.backend.models.experiment import Experimentfrom products.exports.backend.models.exported_asset import ExportedAssetfrom products.feature_flags.backend.models.feature_flag import FeatureFlag@@ -52,6 +77,7 @@ from products.logs.backend.models import LogsAlertConfiguration, LogsViewfrom products.notebooks.backend.models import Notebook, ResourceNotebookfrom products.product_analytics.backend.facade.models import Insight, InsightVariablefrom products.surveys.backend.models import Survey, SurveyResponseArchive+from products.tasks.backend.models import Channel, SandboxEnvironment, Task, TaskRunfrom products.warehouse_sources.backend.facade.models import (DataWarehouseTable as DataWarehouseTableModel,ExternalDataJob,@@ -61,55 +87,6 @@ from products.warehouse_sources.backend.facade.models import (from products.warehouse_sources.backend.facade.types import DIRECT_ENGINE_BY_SOURCE_TYPEfrom products.workflows.backend.models.hog_flow.hog_flow import HogFlow-if TYPE_CHECKING:- from products.customer_analytics.backend.models.account import Account- from products.customer_analytics.backend.models.custom_property_definition import CustomPropertyDefinition- from products.customer_analytics.backend.models.custom_property_value import CustomPropertyValue- from products.customer_analytics.backend.models.feature_request import (- FeatureRequest,- FeatureRequestAccountLink,- FeatureRequestEvidence,- FeatureRequestHistory,- FeatureRequestProductArea,- FeatureRequestProductAreaLink,- )- from products.customer_analytics.backend.models.relationship import (- AccountRelationship,- AccountRelationshipDefinition,- )- from products.error_tracking.backend.models import (- ErrorTrackingAssignmentRule,- ErrorTrackingBypassRule,- ErrorTrackingIssue,- ErrorTrackingIssueAssignment,- ErrorTrackingIssueFingerprintV2,- ErrorTrackingRelease,- ErrorTrackingSeverityRule,- ErrorTrackingSuppressionRule,- ErrorTrackingSymbolSet,- )-else:- Account = apps.get_model("customer_analytics", "Account")- CustomPropertyDefinition = apps.get_model("customer_analytics", "CustomPropertyDefinition")- CustomPropertyValue = apps.get_model("customer_analytics", "CustomPropertyValue")- FeatureRequest = apps.get_model("customer_analytics", "FeatureRequest")- FeatureRequestAccountLink = apps.get_model("customer_analytics", "FeatureRequestAccountLink")- FeatureRequestEvidence = apps.get_model("customer_analytics", "FeatureRequestEvidence")- FeatureRequestHistory = apps.get_model("customer_analytics", "FeatureRequestHistory")- FeatureRequestProductArea = apps.get_model("customer_analytics", "FeatureRequestProductArea")- FeatureRequestProductAreaLink = apps.get_model("customer_analytics", "FeatureRequestProductAreaLink")- AccountRelationship = apps.get_model("customer_analytics", "AccountRelationship")- AccountRelationshipDefinition = apps.get_model("customer_analytics", "AccountRelationshipDefinition")- ErrorTrackingIssue = apps.get_model("error_tracking", "ErrorTrackingIssue")- ErrorTrackingSymbolSet = apps.get_model("error_tracking", "ErrorTrackingSymbolSet")- ErrorTrackingIssueAssignment = apps.get_model("error_tracking", "ErrorTrackingIssueAssignment")- ErrorTrackingIssueFingerprintV2 = apps.get_model("error_tracking", "ErrorTrackingIssueFingerprintV2")- ErrorTrackingAssignmentRule = apps.get_model("error_tracking", "ErrorTrackingAssignmentRule")- ErrorTrackingBypassRule = apps.get_model("error_tracking", "ErrorTrackingBypassRule")- ErrorTrackingSuppressionRule = apps.get_model("error_tracking", "ErrorTrackingSuppressionRule")- ErrorTrackingRelease = apps.get_model("error_tracking", "ErrorTrackingRelease")- ErrorTrackingSeverityRule = apps.get_model("error_tracking", "ErrorTrackingSeverityRule")-# Only directly-queryable tables are team-scoped via a WHERE clause. Namespace nodes such as# `information_schema` carry no `table` of their own (just child catalog tables computed per-query),# so they have no team_id filter and can't be `SELECT *`-ed directly — skip them here.@@ -250,66 +227,57 @@ def _create_activity_log(team: Team, label: str) -> ActivityLog:return ActivityLog.objects.create(team_id=team.pk, activity="updated", scope="FeatureFlag", item_id=label)-def _create_account(team: Team, label: str) -> Account:- return Account.objects.unscoped().create(team=team, name=f"account_{label}", external_id=f"ext_{label}")+def _create_account(team: Team, label: str):+ return create_account(team_id=team.pk, name=f"account_{label}", external_id=f"ext_{label}")-def _create_custom_property_definition(team: Team, label: str) -> "CustomPropertyDefinition":- return CustomPropertyDefinition.objects.unscoped().create(team=team, name=f"def_{label}", display_type="text")+def _create_custom_property_definition(team: Team, label: str):+ return create_custom_property_definition(team_id=team.pk, name=f"def_{label}")-def _create_account_relationship(team: Team, label: str) -> "AccountRelationship":- account = Account.objects.unscoped().create(team=team, name=f"account_{label}")- definition = AccountRelationshipDefinition.objects.unscoped().create(team=team, name=f"rel_{label}")- return AccountRelationship.objects.unscoped().create(team=team, account=account, definition=definition)+def _create_account_relationship(team: Team, label: str):+ account = create_account(team_id=team.pk, name=f"account_{label}")+ definition = create_account_relationship_definition(team_id=team.pk, name=f"rel_{label}")+ return create_account_relationship(team_id=team.pk, account=account, definition=definition)-def _create_account_relationship_definition(team: Team, label: str) -> "AccountRelationshipDefinition":- return AccountRelationshipDefinition.objects.unscoped().create(team=team, name=f"rel_def_{label}")+def _create_account_relationship_definition(team: Team, label: str):+ return create_account_relationship_definition(team_id=team.pk, name=f"rel_def_{label}")-def _create_feature_request(team: Team, label: str) -> "FeatureRequest":- account = Account.objects.unscoped().create(team=team, name=f"feature_request_account_{label}")- feature_request = FeatureRequest.objects.unscoped().create(team=team, title=f"feature_request_{label}")- FeatureRequestAccountLink.objects.unscoped().create(team=team, feature_request=feature_request, account=account)+def _create_feature_request(team: Team, label: str):+ account = create_account(team_id=team.pk, name=f"feature_request_account_{label}")+ feature_request = create_feature_request(team_id=team.pk, title=f"feature_request_{label}")+ create_feature_request_account_link(team_id=team.pk, feature_request=feature_request, account=account)return feature_request-def _create_feature_request_product_area(team: Team, label: str) -> "FeatureRequestProductArea":- return FeatureRequestProductArea.objects.unscoped().create(team=team, name=f"product_area_{label}")+def _create_feature_request_product_area(team: Team, label: str):+ return create_feature_request_product_area(team_id=team.pk, name=f"product_area_{label}")-def _create_feature_request_account_link(team: Team, label: str) -> "FeatureRequestAccountLink":- account = Account.objects.unscoped().create(team=team, name=f"linked_account_{label}")- feature_request = FeatureRequest.objects.unscoped().create(team=team, title=f"linked_request_{label}")- return FeatureRequestAccountLink.objects.unscoped().create(- team=team, feature_request=feature_request, account=account- )+def _create_feature_request_account_link(team: Team, label: str):+ account = create_account(team_id=team.pk, name=f"linked_account_{label}")+ feature_request = create_feature_request(team_id=team.pk, title=f"linked_request_{label}")+ return create_feature_request_account_link(team_id=team.pk, feature_request=feature_request, account=account)-def _create_feature_request_evidence(team: Team, label: str) -> "FeatureRequestEvidence":+def _create_feature_request_evidence(team: Team, label: str):account_link = _create_feature_request_account_link(team, label)- return FeatureRequestEvidence.objects.unscoped().create(- team=team, account_link=account_link, source="conversation", summary=f"evidence_{label}"- )+ return create_feature_request_evidence(team_id=team.pk, account_link=account_link, summary=f"evidence_{label}")-def _create_feature_request_product_area_link(team: Team, label: str) -> "FeatureRequestProductAreaLink":+def _create_feature_request_product_area_link(team: Team, label: str):feature_request = _create_feature_request(team, label)product_area = _create_feature_request_product_area(team, label)- return FeatureRequestProductAreaLink.objects.unscoped().create(- team=team, feature_request=feature_request, product_area=product_area+ return create_feature_request_product_area_link(+ team_id=team.pk, feature_request=feature_request, product_area=product_area)-def _create_feature_request_history(team: Team, label: str) -> "FeatureRequestHistory":+def _create_feature_request_history(team: Team, label: str):feature_request = _create_feature_request(team, label)- return FeatureRequestHistory.objects.unscoped().create(- team=team,- feature_request=feature_request,- changes=[],- changed_at=timezone.now(),- )+ return create_feature_request_history(team_id=team.pk, feature_request=feature_request, changed_at=timezone.now())def _create_action(team: Team, label: str) -> Action:@@ -464,54 +432,42 @@ def _create_endpoint_version(team: Team, label: str) -> EndpointVersion:)-def _create_error_tracking_issue(team: Team, label: str) -> ErrorTrackingIssue:- return ErrorTrackingIssue.objects.create(team=team, name=f"issue_{label}", status="active")+def _create_error_tracking_issue(team: Team, label: str) -> uuid.UUID:+ return create_issue(team_id=team.pk, name=f"issue_{label}")-def _create_error_tracking_issue_assignment(team: Team, label: str):- issue = ErrorTrackingIssue.objects.create(team=team, name=f"assigned_issue_{label}", status="active")- return ErrorTrackingIssueAssignment.objects.create(team=team, issue=issue)+def _create_error_tracking_issue_assignment(team: Team, label: str) -> uuid.UUID:+ issue_id = create_issue(team_id=team.pk, name=f"assigned_issue_{label}")+ return create_issue_assignment(team_id=team.pk, issue_id=issue_id)-def _create_error_tracking_issue_fingerprint(team: Team, label: str):- issue = ErrorTrackingIssue.objects.create(team=team, name=f"fp_issue_{label}", status="active")- return ErrorTrackingIssueFingerprintV2.objects.create(team=team, issue=issue, fingerprint=f"fp_{label}")+def _create_error_tracking_issue_fingerprint(team: Team, label: str) -> uuid.UUID:+ issue_id = create_issue(team_id=team.pk, name=f"fp_issue_{label}")+ return create_issue_fingerprint(team_id=team.pk, issue_id=issue_id, fingerprint=f"fp_{label}")-def _create_error_tracking_assignment_rule(team: Team, label: str):- return ErrorTrackingAssignmentRule.objects.create(- team=team, filters={"type": "AND", "values": []}, bytecode=[], order_key=0- )+def _create_error_tracking_assignment_rule(team: Team, label: str) -> uuid.UUID:+ return create_assignment_rule(team_id=team.pk)-def _create_error_tracking_bypass_rule(team: Team, label: str):- return ErrorTrackingBypassRule.objects.create(- team=team, filters={"type": "AND", "values": []}, bytecode=[], order_key=0- )+def _create_error_tracking_bypass_rule(team: Team, label: str) -> uuid.UUID:+ return create_bypass_rule(team_id=team.pk)-def _create_error_tracking_severity_rule(team: Team, label: str):- return ErrorTrackingSeverityRule.objects.unscoped().create(- team=team, filters={"type": "AND", "values": []}, bytecode=[], severity="high", order_key=0- )+def _create_error_tracking_severity_rule(team: Team, label: str) -> uuid.UUID:+ return create_severity_rule(team_id=team.pk)-def _create_error_tracking_suppression_rule(team: Team, label: str):- return ErrorTrackingSuppressionRule.objects.create(- team=team, filters={"type": "AND", "values": []}, bytecode=[], order_key=0, sampling_rate=1.0- )+def _create_error_tracking_suppression_rule(team: Team, label: str) -> uuid.UUID:+ return create_suppression_rule(team_id=team.pk)-def _create_error_tracking_release(team: Team, label: str):- return ErrorTrackingRelease.objects.create(- team=team, hash_id=f"hash_{label}", version=f"v_{label}", project=f"proj_{label}"- )+def _create_error_tracking_release(team: Team, label: str) -> uuid.UUID:+ return create_release(team_id=team.pk, hash_id=f"hash_{label}", version=f"v_{label}", project=f"proj_{label}")-def _create_error_tracking_symbol_set(team: Team, label: str) -> ErrorTrackingSymbolSet:- return ErrorTrackingSymbolSet.objects.create(- team=team, ref=f"symbol_set_{label}", storage_ptr=f"symbolsets/{label}"- )+def _create_error_tracking_symbol_set(team: Team, label: str) -> uuid.UUID:+ return create_symbol_set(team_id=team.pk, ref=f"symbol_set_{label}", storage_ptr=f"symbolsets/{label}")def _create_hog_flow(team: Team, label: str) -> HogFlow:@@ -738,23 +694,14 @@ def _create_support_ticket(team: Team, label: str) -> Ticket:def _create_account_meeting(team: Team, label: str):- Account = apps.get_model("customer_analytics", "Account")- Meeting = apps.get_model("customer_analytics", "Meeting")- account = Account.objects.unscoped().create(team=team, name=f"account_{label}")- return Meeting.objects.unscoped().create(- team=team,- account=account,- ical_uid=f"meeting_{label}",- start_time=timezone.now(),- )+ account = create_account(team_id=team.pk, name=f"account_{label}")+ return create_meeting(team_id=team.pk, account=account, ical_uid=f"meeting_{label}", start_time=timezone.now())def _create_account_channel_summary(team: Team, label: str):- Account = apps.get_model("customer_analytics", "Account")- AccountChannelSummary = apps.get_model("customer_analytics", "AccountChannelSummary")- account = Account.objects.unscoped().create(team=team, name=f"account_{label}")- return AccountChannelSummary.objects.unscoped().create(- team=team,+ account = create_account(team_id=team.pk, name=f"account_{label}")+ return create_account_channel_summary(+ team_id=team.pk,account=account,slack_channel_id=f"channel_{label}",cadence="daily",@@ -764,11 +711,8 @@ def _create_account_channel_summary(team: Team, label: str):)-def _create_account_email_thread(team: Team, label: str):- Account = apps.get_model("customer_analytics", "Account")- EmailThread = apps.get_model("conversations", "EmailThread")- EmailThreadAccountLink = apps.get_model("conversations", "EmailThreadAccountLink")- account = Account.objects.unscoped().create(team=team, name=f"account_{label}")+def _create_account_email_thread(team: Team, label: str) -> EmailThread:+ account = create_account(team_id=team.pk, name=f"account_{label}")thread = EmailThread.objects.for_team(team.id).create(team=team,canonical_thread_key=f"thread_{label}",@@ -783,11 +727,8 @@ def _create_account_email_thread(team: Team, label: str):return thread-def _create_account_email_thread_link(team: Team, label: str):- Account = apps.get_model("customer_analytics", "Account")- EmailThread = apps.get_model("conversations", "EmailThread")- EmailThreadAccountLink = apps.get_model("conversations", "EmailThreadAccountLink")- account = Account.objects.unscoped().create(team=team, name=f"account_{label}")+def _create_account_email_thread_link(team: Team, label: str) -> EmailThreadAccountLink:+ account = create_account(team_id=team.pk, name=f"account_{label}")thread = EmailThread.objects.for_team(team.id).create(team=team,canonical_thread_key=f"thread_{label}",@@ -813,16 +754,12 @@ def _create_survey_response_archive(team: Team, label: str) -> SurveyResponseArc)-def _create_public_task_channel(team: Team, label: str):- Channel = apps.get_model("tasks", "Channel")-+def _create_public_task_channel(team: Team, label: str) -> Channel:with team_scope(team.pk):return Channel.objects.create(team=team, name=f"channel_{label}")-def _create_task(team: Team, label: str):- Task = apps.get_model("tasks", "Task")-+def _create_task(team: Team, label: str) -> Task:return Task.objects.create(team=team,channel=_create_public_task_channel(team, f"task_{label}"),@@ -832,18 +769,13 @@ def _create_task(team: Team, label: str):)-def _create_canvas(team: Team, label: str):- Canvas = apps.get_model("canvas", "Canvas")-+def _create_canvas(team: Team, label: str) -> Canvas:with team_scope(team.pk):channel = _create_public_task_channel(team, f"canvas_{label}")return Canvas.objects.create(team=team, channel=channel, name=f"canvas_{label}")-def _create_task_run(team: Team, label: str):- Task = apps.get_model("tasks", "Task")- TaskRun = apps.get_model("tasks", "TaskRun")-+def _create_task_run(team: Team, label: str) -> TaskRun:task = Task.objects.create(team=team,channel=_create_public_task_channel(team, f"run_{label}"),@@ -866,9 +798,7 @@ def _create_file_system(team: Team, label: str):)-def _create_sandbox_environment(team: Team, label: str):- SandboxEnvironment = apps.get_model("tasks", "SandboxEnvironment")-+def _create_sandbox_environment(team: Team, label: str) -> SandboxEnvironment:# private=False so the row is queryable via HogQL — the privacy predicate# excludes private environments. Privacy filtering itself is covered by# TestSystemTablesSandboxEnvironmentPrivacy.@@ -1052,16 +982,12 @@ class TestSystemTablesTeamIsolation(NonAtomicBaseTest):response = execute_hogql_query(f"SELECT id FROM system.{table_name}", team=self.team, user=self.user)ids = {str(row[0]) for row in response.results}- assert str(obj_team1.pk) in ids- assert str(obj_team2.pk) not in ids+ # A factory returns either a model instance or a bare id (error_tracking's testing door returns ids).+ assert str(getattr(obj_team1, "pk", obj_team1)) in ids+ assert str(getattr(obj_team2, "pk", obj_team2)) not in idsdef test_error_tracking_issue_severity(self):- ErrorTrackingIssue.objects.create(- team=self.team,- name="high_severity_issue",- status=ErrorTrackingIssue.Status.ACTIVE,- severity=ErrorTrackingIssue.Severity.HIGH,- )+ create_issue(team_id=self.team.pk, name="high_severity_issue", severity="high")response = execute_hogql_query("SELECT severity FROM system.error_tracking_issues WHERE severity IS NOT NULL",@@ -1114,8 +1040,6 @@ class TestSystemTablesSandboxEnvironmentPrivacyIsolation(NonAtomicBaseTest):CLASS_DATA_LEVEL_SETUP = Falsedef test_private_environments_excluded(self):- SandboxEnvironment = apps.get_model("tasks", "SandboxEnvironment")-public_env = SandboxEnvironment.objects.create(team=self.team, name="public_env", private=False)private_env = SandboxEnvironment.objects.create(team=self.team, name="private_env", private=True)@@ -1126,8 +1050,6 @@ class TestSystemTablesSandboxEnvironmentPrivacyIsolation(NonAtomicBaseTest):assert str(private_env.pk) not in idsdef test_internal_environments_excluded(self):- SandboxEnvironment = apps.get_model("tasks", "SandboxEnvironment")-regular_env = SandboxEnvironment.objects.create(team=self.team, name="regular_env", private=False, internal=False)@@ -1161,9 +1083,6 @@ class TestSystemTablesCanvasDeletedExclusionIsolation(NonAtomicBaseTest):CLASS_DATA_LEVEL_SETUP = Falsedef test_deleted_canvases_excluded(self):- Channel = apps.get_model("tasks", "Channel")- Canvas = apps.get_model("canvas", "Canvas")-with team_scope(self.team.pk):channel = Channel.objects.create(team=self.team, name="canvas-exclusion-channel")live_canvas = Canvas.objects.create(team=self.team, channel=channel, name="live")@@ -1195,7 +1114,6 @@ class TestSystemTablesTaskInternalExclusionIsolation(NonAtomicBaseTest):CLASS_DATA_LEVEL_SETUP = Falsedef test_internal_tasks_excluded(self):- Task = apps.get_model("tasks", "Task")channel = _create_public_task_channel(self.team, "internal-exclusion")regular_task = Task.objects.create(@@ -1226,11 +1144,6 @@ class TestSystemTablesTaskSpaceVisibilityIsolation(NonAtomicBaseTest):CLASS_DATA_LEVEL_SETUP = Falsedef test_private_and_unfiled_task_resources_are_excluded(self):- Channel = apps.get_model("tasks", "Channel")- Task = apps.get_model("tasks", "Task")- TaskRun = apps.get_model("tasks", "TaskRun")- Canvas = apps.get_model("canvas", "Canvas")-with team_scope(self.team.pk):public_channel = Channel.objects.create(team=self.team, name="public-space")private_channel = Channel.objects.create(@@ -1489,12 +1402,12 @@ class TestSystemAccountsLazyJoins(NonAtomicBaseTest):self.other_team = Team.objects.create(id=other_project.id, project=other_project, organization=other_org)def test_tags_lazy_join_returns_tag_names_array(self):- account = Account.objects.unscoped().create(team=self.team, name="A")+ account = create_account(team_id=self.team.pk, name="A")billing = Tag.objects.create(name="billing", team=self.team)urgent = Tag.objects.create(name="urgent", team=self.team)account.tagged_items.create(tag=billing)account.tagged_items.create(tag=urgent)- Account.objects.unscoped().create(team=self.team, name="B") # untagged+ create_account(team_id=self.team.pk, name="B") # untaggedresponse = execute_hogql_query("SELECT id, accounts.tags.names FROM system.accounts AS accounts ORDER BY name",@@ -1506,7 +1419,7 @@ class TestSystemAccountsLazyJoins(NonAtomicBaseTest):assert sorted(rows_by_id[str(account.id)]) == ["billing", "urgent"]def test_tags_lazy_join_isolated_per_team(self):- other_account = Account.objects.unscoped().create(team=self.other_team, name="Theirs")+ other_account = create_account(team_id=self.other_team.pk, name="Theirs")other_tag = Tag.objects.create(name="billing", team=self.other_team)other_account.tagged_items.create(tag=other_tag)@@ -1518,11 +1431,11 @@ class TestSystemAccountsLazyJoins(NonAtomicBaseTest):assert response.results == []def test_notebooks_lazy_join_returns_count(self):- account = Account.objects.unscoped().create(team=self.team, name="A")+ account = create_account(team_id=self.team.pk, name="A")for label in ("n1", "n2", "n3"):notebook = Notebook.objects.create(team=self.team, title=label)ResourceNotebook.objects.create(notebook=notebook, account=account)- Account.objects.unscoped().create(team=self.team, name="B") # no notebooks+ create_account(team_id=self.team.pk, name="B") # no notebooksresponse = execute_hogql_query("SELECT id, accounts.notebooks.count FROM system.accounts AS accounts ORDER BY name",@@ -1534,21 +1447,17 @@ class TestSystemAccountsLazyJoins(NonAtomicBaseTest):assert rows_by_id[str(account.id)] == 3def test_customer_context_lazy_joins_return_recent_account_records(self):- account = Account.objects.unscoped().create(team=self.team, name="Acme", external_id="acme-org")- Meeting = apps.get_model("customer_analytics", "Meeting")- AccountChannelSummary = apps.get_model("customer_analytics", "AccountChannelSummary")- EmailThread = apps.get_model("conversations", "EmailThread")- EmailThreadAccountLink = apps.get_model("conversations", "EmailThreadAccountLink")+ account = create_account(team_id=self.team.pk, name="Acme", external_id="acme-org")- Meeting.objects.unscoped().create(- team=self.team,+ create_meeting(+ team_id=self.team.pk,account=account,ical_uid="acme-meeting",start_time=timezone.now(),title="Account review",)- AccountChannelSummary.objects.unscoped().create(- team=self.team,+ create_account_channel_summary(+ team_id=self.team.pk,account=account,slack_channel_id="C123",cadence="weekly",@@ -1556,8 +1465,8 @@ class TestSystemAccountsLazyJoins(NonAtomicBaseTest):period_end=timezone.now(),content="Account is healthy",)- request = FeatureRequest.objects.unscoped().create(team=self.team, title="Export reports")- FeatureRequestAccountLink.objects.unscoped().create(team=self.team, feature_request=request, account=account)+ request = create_feature_request(team_id=self.team.pk, title="Export reports")+ create_feature_request_account_link(team_id=self.team.pk, feature_request=request, account=account)ticket = Ticket.objects.create_with_number(team=self.team,channel_source="widget",@@ -1614,13 +1523,13 @@ class TestSystemAccountsLazyJoins(NonAtomicBaseTest):assert json.loads(row[9])[0]["subject"] == "Quarterly review"def _custom_property_value(self, account, definition, **value_kwargs):- return CustomPropertyValue.objects.unscoped().create(- team=self.team, account=account, definition=definition, **value_kwargs+ return create_custom_property_value(+ team_id=self.team.pk, account=account, definition=definition, **value_kwargs)def test_custom_properties_lazy_join_returns_value_by_definition_id(self):- account = Account.objects.unscoped().create(team=self.team, name="A")- definition = CustomPropertyDefinition.objects.unscoped().create(team=self.team, name="Plan")+ account = create_account(team_id=self.team.pk, name="A")+ definition = create_custom_property_definition(team_id=self.team.pk, name="Plan")self._custom_property_value(account, definition, value_str="enterprise")response = execute_hogql_query(@@ -1634,8 +1543,8 @@ class TestSystemAccountsLazyJoins(NonAtomicBaseTest):assert rows_by_id[str(account.id)] == "enterprise"def test_custom_properties_lazy_join_excludes_deleted_values(self):- account = Account.objects.unscoped().create(team=self.team, name="A")- definition = CustomPropertyDefinition.objects.unscoped().create(team=self.team, name="Plan")+ account = create_account(team_id=self.team.pk, name="A")+ definition = create_custom_property_definition(team_id=self.team.pk, name="Plan")self._custom_property_value(account, definition, value_str="old", is_deleted=True)self._custom_property_value(account, definition, value_str="current")@@ -1649,11 +1558,14 @@ class TestSystemAccountsLazyJoins(NonAtomicBaseTest):def test_custom_properties_lazy_join_isolated_per_team(self):# An account exists in self.team, so the query returns a row; the assertion only passes# if the other team's value is filtered out rather than leaking through the join.- account = Account.objects.unscoped().create(team=self.team, name="Ours")- other_account = Account.objects.unscoped().create(team=self.other_team, name="Theirs")- other_definition = CustomPropertyDefinition.objects.unscoped().create(team=self.other_team, name="Plan")- CustomPropertyValue.objects.unscoped().create(- team=self.other_team, account=other_account, definition=other_definition, value_str="secret"+ account = create_account(team_id=self.team.pk, name="Ours")+ other_account = create_account(team_id=self.other_team.pk, name="Theirs")+ other_definition = create_custom_property_definition(team_id=self.other_team.pk, name="Plan")+ create_custom_property_value(+ team_id=self.other_team.pk,+ account=other_account,+ definition=other_definition,+ value_str="secret",)response = execute_hogql_query(@@ -1668,18 +1580,18 @@ class TestSystemAccountsLazyJoins(NonAtomicBaseTest):assert rows_by_id[str(account.id)] in (None, "")def _create_relationship_definition(self, name="CSM", **kwargs):- return AccountRelationshipDefinition.objects.unscoped().create(team=self.team, name=name, **kwargs)+ return create_account_relationship_definition(team_id=self.team.pk, name=name, **kwargs)def _create_relationship(self, account, definition, user, **kwargs):- return AccountRelationship.objects.unscoped().create(- team=self.team, account=account, definition=definition, user=user, **kwargs+ return create_account_relationship(+ team_id=self.team.pk, account=account, definition=definition, user=user, **kwargs)def test_relationships_lazy_join_returns_active_user_ids_by_definition_id(self):- account = Account.objects.unscoped().create(team=self.team, name="A")+ account = create_account(team_id=self.team.pk, name="A")definition = self._create_relationship_definition()self._create_relationship(account, definition, self.user)- Account.objects.unscoped().create(team=self.team, name="B") # no relationships+ create_account(team_id=self.team.pk, name="B") # no relationshipsresponse = execute_hogql_query(f"SELECT id, accounts.relationships.values.`{definition.id}` "@@ -1692,7 +1604,7 @@ class TestSystemAccountsLazyJoins(NonAtomicBaseTest):assert rows_by_id[str(account.id)] == [self.user.id]def test_relationships_lazy_join_excludes_ended_rows(self):- account = Account.objects.unscoped().create(team=self.team, name="A")+ account = create_account(team_id=self.team.pk, name="A")definition = self._create_relationship_definition()self._create_relationship(account, definition, self.user, ended_at=timezone.now())@@ -1704,7 +1616,7 @@ class TestSystemAccountsLazyJoins(NonAtomicBaseTest):assert response.results[0][0] in ([], None)def test_relationships_lazy_join_multi_holder_returns_all_active(self):- account = Account.objects.unscoped().create(team=self.team, name="A")+ account = create_account(team_id=self.team.pk, name="A")definition = self._create_relationship_definition(name="FDE", is_single_holder=False)other_user = self._create_user("[email protected]")self._create_relationship(account, definition, self.user)@@ -1718,11 +1630,14 @@ class TestSystemAccountsLazyJoins(NonAtomicBaseTest):assert sorted(response.results[0][0]) == sorted([self.user.id, other_user.id])def test_relationships_lazy_join_isolated_per_team(self):- account = Account.objects.unscoped().create(team=self.team, name="Ours")- other_account = Account.objects.unscoped().create(team=self.other_team, name="Theirs")- other_definition = AccountRelationshipDefinition.objects.unscoped().create(team=self.other_team, name="CSM")- AccountRelationship.objects.unscoped().create(- team=self.other_team, account=other_account, definition=other_definition, user=self.user+ account = create_account(team_id=self.team.pk, name="Ours")+ other_account = create_account(team_id=self.other_team.pk, name="Theirs")+ other_definition = create_account_relationship_definition(team_id=self.other_team.pk, name="CSM")+ create_account_relationship(+ team_id=self.other_team.pk,+ account=other_account,+ definition=other_definition,+ user=self.user,)response = execute_hogql_query(diff --git a/products/customer_analytics/backend/facade/testing.py b/products/customer_analytics/backend/facade/testing.pyindex 9afccc523e7f..899bc7e2b74c 100644--- a/products/customer_analytics/backend/facade/testing.py+++ b/products/customer_analytics/backend/facade/testing.py@@ -1,9 +1,38 @@"""Test-support facade for customer_analytics.-Sibling products' tests plant accounts through this module so they never import the-product's model or its test factories directly.+Outside test suites plant accounts and their related rows (custom properties,+relationships, feature requests, meetings, channel summaries) through this module so+they never import the product's models or its test factories directly."""-from products.customer_analytics.backend.test.factories import create_account+from products.customer_analytics.backend.test.factories import (+ create_account,+ create_account_channel_summary,+ create_account_relationship,+ create_account_relationship_definition,+ create_custom_property_definition,+ create_custom_property_value,+ create_feature_request,+ create_feature_request_account_link,+ create_feature_request_evidence,+ create_feature_request_history,+ create_feature_request_product_area,+ create_feature_request_product_area_link,+ create_meeting,+)-__all__ = ["create_account"]+__all__ = [+ "create_account",+ "create_account_channel_summary",+ "create_account_relationship",+ "create_account_relationship_definition",+ "create_custom_property_definition",+ "create_custom_property_value",+ "create_feature_request",+ "create_feature_request_account_link",+ "create_feature_request_evidence",+ "create_feature_request_history",+ "create_feature_request_product_area",+ "create_feature_request_product_area_link",+ "create_meeting",+]diff --git a/products/customer_analytics/backend/test/factories.py b/products/customer_analytics/backend/test/factories.pyindex 147e671722f6..687674cf9357 100644--- a/products/customer_analytics/backend/test/factories.py+++ b/products/customer_analytics/backend/test/factories.py@@ -1,8 +1,26 @@+from datetime import datetimefrom typing import Anyfrom django.apps import apps-from products.customer_analytics.backend.models import Account, CustomPropertyDefinition, DisplayType+from posthog.models import User++from products.customer_analytics.backend.models import (+ Account,+ AccountChannelSummary,+ AccountRelationship,+ AccountRelationshipDefinition,+ CustomPropertyDefinition,+ CustomPropertyValue,+ DisplayType,+ FeatureRequest,+ FeatureRequestAccountLink,+ FeatureRequestEvidence,+ FeatureRequestHistory,+ FeatureRequestProductArea,+ FeatureRequestProductAreaLink,+ Meeting,+)def create_account(*, team_id: int, name: str = "Acme Corp", **kwargs: Any) -> Account:@@ -10,6 +28,104 @@ def create_account(*, team_id: int, name: str = "Acme Corp", **kwargs: Any) -> Areturn Account.objects.unscoped().create(team_id=team_id, name=name, **kwargs)+def create_custom_property_value(+ *, team_id: int, account: Account, definition: CustomPropertyDefinition, **kwargs: Any+) -> CustomPropertyValue:+ return CustomPropertyValue.objects.for_team(team_id).create(+ team_id=team_id, account=account, definition=definition, **kwargs+ )+++def create_account_relationship_definition(+ *, team_id: int, name: str = "CSM", **kwargs: Any+) -> AccountRelationshipDefinition:+ return AccountRelationshipDefinition.objects.for_team(team_id).create(team_id=team_id, name=name, **kwargs)+++def create_account_relationship(+ *,+ team_id: int,+ account: Account,+ definition: AccountRelationshipDefinition,+ user: User | None = None,+ **kwargs: Any,+) -> AccountRelationship:+ return AccountRelationship.objects.for_team(team_id).create(+ team_id=team_id, account=account, definition=definition, user=user, **kwargs+ )+++def create_feature_request(*, team_id: int, title: str = "Export reports", **kwargs: Any) -> FeatureRequest:+ return FeatureRequest.objects.for_team(team_id).create(team_id=team_id, title=title, **kwargs)+++def create_feature_request_account_link(+ *, team_id: int, feature_request: FeatureRequest, account: Account, **kwargs: Any+) -> FeatureRequestAccountLink:+ return FeatureRequestAccountLink.objects.for_team(team_id).create(+ team_id=team_id, feature_request=feature_request, account=account, **kwargs+ )+++def create_feature_request_product_area(+ *, team_id: int, name: str = "Reporting", **kwargs: Any+) -> FeatureRequestProductArea:+ return FeatureRequestProductArea.objects.for_team(team_id).create(team_id=team_id, name=name, **kwargs)+++def create_feature_request_product_area_link(+ *, team_id: int, feature_request: FeatureRequest, product_area: FeatureRequestProductArea, **kwargs: Any+) -> FeatureRequestProductAreaLink:+ return FeatureRequestProductAreaLink.objects.for_team(team_id).create(+ team_id=team_id, feature_request=feature_request, product_area=product_area, **kwargs+ )+++def create_feature_request_evidence(+ *, team_id: int, account_link: FeatureRequestAccountLink, source: str = "conversation", **kwargs: Any+) -> FeatureRequestEvidence:+ return FeatureRequestEvidence.objects.for_team(team_id).create(+ team_id=team_id, account_link=account_link, source=source, **kwargs+ )+++def create_feature_request_history(+ *, team_id: int, feature_request: FeatureRequest, changed_at: datetime, changes: list | None = None, **kwargs: Any+) -> FeatureRequestHistory:+ return FeatureRequestHistory.objects.for_team(team_id).create(+ team_id=team_id, feature_request=feature_request, changed_at=changed_at, changes=changes or [], **kwargs+ )+++def create_meeting(*, team_id: int, account: Account, ical_uid: str, start_time: datetime, **kwargs: Any) -> Meeting:+ return Meeting.objects.for_team(team_id).create(+ team_id=team_id, account=account, ical_uid=ical_uid, start_time=start_time, **kwargs+ )+++def create_account_channel_summary(+ *,+ team_id: int,+ account: Account,+ slack_channel_id: str,+ cadence: str,+ period_start: datetime,+ period_end: datetime,+ content: str,+ **kwargs: Any,+) -> AccountChannelSummary:+ return AccountChannelSummary.objects.for_team(team_id).create(+ team_id=team_id,+ account=account,+ slack_channel_id=slack_channel_id,+ cadence=cadence,+ period_start=period_start,+ period_end=period_end,+ content=content,+ **kwargs,+ )++def create_custom_property_definition(*, team_id: int, name: str = "Plan", display_type: str = DisplayType.TEXT, **kwargs: Any) -> CustomPropertyDefinition:diff --git a/products/error_tracking/backend/facade/testing.py b/products/error_tracking/backend/facade/testing.pyindex 255b56aac8bf..beb16331612e 100644--- a/products/error_tracking/backend/facade/testing.py+++ b/products/error_tracking/backend/facade/testing.py@@ -1,7 +1,8 @@"""Test-support facade for error_tracking.-Outside test suites (core's weekly digest, the metrics error overlay) plant issues and-spike events. They get them here instead of importing the models.+Outside test suites (core's weekly digest, the metrics error overlay, the system-tables+isolation tests) plant issues and their related rows. They get them here instead of+importing the models."""from datetime import datetime@@ -9,7 +10,20 @@ from uuid import UUIDfrom posthog.schema import ErrorTrackingIssueStatus-from products.error_tracking.backend.models import ErrorTrackingIssue, ErrorTrackingSpikeEvent+from products.error_tracking.backend.models import (+ ErrorTrackingAssignmentRule,+ ErrorTrackingBypassRule,+ ErrorTrackingIssue,+ ErrorTrackingIssueAssignment,+ ErrorTrackingIssueFingerprintV2,+ ErrorTrackingRelease,+ ErrorTrackingSeverityRule,+ ErrorTrackingSpikeEvent,+ ErrorTrackingSuppressionRule,+ ErrorTrackingSymbolSet,+)++_EMPTY_FILTERS: dict = {"type": "AND", "values": []}def create_issue(@@ -17,9 +31,10 @@ def create_issue(team_id: int,name: str,status: ErrorTrackingIssueStatus = ErrorTrackingIssueStatus.ACTIVE,+ severity: str | None = None,created_at: datetime | None = None,) -> UUID:- issue = ErrorTrackingIssue.objects.create(team_id=team_id, name=name, status=status)+ issue = ErrorTrackingIssue.objects.create(team_id=team_id, name=name, status=status, severity=severity)if created_at is not None:# created_at is auto_now_add, so it can only be set after the insert.ErrorTrackingIssue.objects.filter(id=issue.id).update(created_at=created_at)@@ -42,3 +57,48 @@ def create_spike_event(current_bucket_value=current_bucket_value,)return spike.id+++def create_issue_assignment(*, team_id: int, issue_id: UUID) -> UUID:+ return ErrorTrackingIssueAssignment.objects.create(team_id=team_id, issue_id=issue_id).id+++def create_issue_fingerprint(*, team_id: int, issue_id: UUID, fingerprint: str) -> UUID:+ return ErrorTrackingIssueFingerprintV2.objects.create(+ team_id=team_id, issue_id=issue_id, fingerprint=fingerprint+ ).id+++def create_assignment_rule(*, team_id: int, order_key: int = 0) -> UUID:+ return ErrorTrackingAssignmentRule.objects.create(+ team_id=team_id, filters=_EMPTY_FILTERS, bytecode=[], order_key=order_key+ ).id+++def create_bypass_rule(*, team_id: int, order_key: int = 0) -> UUID:+ return ErrorTrackingBypassRule.objects.create(+ team_id=team_id, filters=_EMPTY_FILTERS, bytecode=[], order_key=order_key+ ).id+++def create_severity_rule(*, team_id: int, severity: str = "high", order_key: int = 0) -> UUID:+ # ErrorTrackingSeverityRule is the only fail-closed model here, so it needs the for_team scope.+ return (+ ErrorTrackingSeverityRule.objects.for_team(team_id)+ .create(team_id=team_id, filters=_EMPTY_FILTERS, bytecode=[], severity=severity, order_key=order_key)+ .id+ )+++def create_suppression_rule(*, team_id: int, order_key: int = 0, sampling_rate: float = 1.0) -> UUID:+ return ErrorTrackingSuppressionRule.objects.create(+ team_id=team_id, filters=_EMPTY_FILTERS, bytecode=[], order_key=order_key, sampling_rate=sampling_rate+ ).id+++def create_release(*, team_id: int, hash_id: str, version: str, project: str) -> UUID:+ return ErrorTrackingRelease.objects.create(team_id=team_id, hash_id=hash_id, version=version, project=project).id+++def create_symbol_set(*, team_id: int, ref: str, storage_ptr: str = "") -> UUID:+ return ErrorTrackingSymbolSet.objects.create(team_id=team_id, ref=ref, storage_ptr=storage_ptr).id