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(data-modeling): seal external boundary and enable isolated backend CI (#68002)

Jovan Sakovice65fa3a0c46f
diff --git a/ee/hogai/eval/sandboxed/data_warehouse/seeder.py b/ee/hogai/eval/sandboxed/data_warehouse/seeder.py
index 29c3d2b1786b..e5ed7e43ef1f 100644
--- a/ee/hogai/eval/sandboxed/data_warehouse/seeder.py
+++ b/ee/hogai/eval/sandboxed/data_warehouse/seeder.py
@@ -56,7 +56,7 @@ def seed_warehouse_schema(context: CustomPromptSandboxContext) -> dict[str, Any]
from posthog.models.scoping import team_scope
from posthog.models.team import Team
- from products.data_modeling.backend.models.datawarehouse_saved_query import DataWarehouseSavedQuery
+ from products.data_modeling.backend.facade.models import DataWarehouseSavedQuery
from products.data_tools.backend.models.join import DataWarehouseJoin
from products.warehouse_sources.backend.models.column_annotation import WarehouseColumnAnnotation
from products.warehouse_sources.backend.models.table import DataWarehouseTable
diff --git a/posthog/migrations/0338_datawarehouse_saved_query.py b/posthog/migrations/0338_datawarehouse_saved_query.py
index caa8f5dfc665..4862c1eaea2b 100644
--- a/posthog/migrations/0338_datawarehouse_saved_query.py
+++ b/posthog/migrations/0338_datawarehouse_saved_query.py
@@ -6,7 +6,7 @@ from django.db import migrations, models
import posthog.models.utils
-import products.data_modeling.backend.models.datawarehouse_saved_query
+import products.data_modeling.backend.facade.models
class Migration(migrations.Migration):
@@ -33,9 +33,7 @@ class Migration(migrations.Migration):
"name",
models.CharField(
max_length=128,
- validators=[
- products.data_modeling.backend.models.datawarehouse_saved_query.validate_saved_query_name
- ],
+ validators=[products.data_modeling.backend.facade.models.validate_saved_query_name],
),
),
(
diff --git a/posthog/migrations/0463_datawarehousemodelpath_and_more.py b/posthog/migrations/0463_datawarehousemodelpath_and_more.py
index fe58224a6261..e8ce87f340e8 100644
--- a/posthog/migrations/0463_datawarehousemodelpath_and_more.py
+++ b/posthog/migrations/0463_datawarehousemodelpath_and_more.py
@@ -8,7 +8,7 @@ from django.db import migrations, models
import posthog.models.utils
-import products.data_modeling.backend.models.modeling
+import products.data_modeling.backend.facade.modeling
class Migration(migrations.Migration):
@@ -29,7 +29,7 @@ class Migration(migrations.Migration):
default=posthog.models.utils.UUIDT, editable=False, primary_key=True, serialize=False
),
),
- ("path", products.data_modeling.backend.models.modeling.LabelTreeField()),
+ ("path", products.data_modeling.backend.facade.modeling.LabelTreeField()),
(
"created_by",
models.ForeignKey(
diff --git a/products/data_modeling/backend/facade/modeling.py b/products/data_modeling/backend/facade/modeling.py
index 7db63558ddbf..c654bb035db3 100644
--- a/products/data_modeling/backend/facade/modeling.py
+++ b/products/data_modeling/backend/facade/modeling.py
@@ -12,6 +12,7 @@ from products.data_modeling.backend.models.modeling import (
DEFAULT_RESOLUTION_MAX_VIEW_DEPTH,
BoundedResolver,
DataWarehouseModelPath,
+ LabelTreeField,
NodeType,
ResolutionCycleError,
ResolutionDepthExceededError,
@@ -25,6 +26,7 @@ __all__ = [
"DEFAULT_RESOLUTION_MAX_VIEW_DEPTH",
"BoundedResolver",
"DataWarehouseModelPath",
+ "LabelTreeField",
"NodeType",
"ResolutionCycleError",
"ResolutionDepthExceededError",
diff --git a/products/data_modeling/package.json b/products/data_modeling/package.json
index f55ad2ab9a9d..67b64efd6fca 100644
--- a/products/data_modeling/package.json
+++ b/products/data_modeling/package.json
@@ -1,7 +1,8 @@
{
"name": "@posthog/products-data-modeling",
"scripts": {
- "backend:test": "pytest -c ../../pytest.ini --rootdir ../.. backend/ -v --tb=short"
+ "backend:test": "pytest -c ../../pytest.ini --rootdir ../.. backend/ -v --tb=short",
+ "backend:contract-check": "echo 'Contract files unchanged'"
},
"dependencies": {
"kea": "catalog:",
diff --git a/products/data_modeling/turbo.json b/products/data_modeling/turbo.json
new file mode 100644
index 000000000000..e16d4eabe6e9
--- /dev/null
+++ b/products/data_modeling/turbo.json
@@ -0,0 +1,10 @@
+{
+ "extends": ["//"],
+ "tasks": {
+ "backend:contract-check": {
+ "inputs": ["backend/facade/**", "backend/presentation/**", "backend/routes.py"],
+ "outputs": [],
+ "cache": true
+ }
+ }
+}
diff --git a/products/data_warehouse/backend/migrations/0001_migrate_data_warehouse_models.py b/products/data_warehouse/backend/migrations/0001_migrate_data_warehouse_models.py
index f4596830c797..4272bcb06759 100644
--- a/products/data_warehouse/backend/migrations/0001_migrate_data_warehouse_models.py
+++ b/products/data_warehouse/backend/migrations/0001_migrate_data_warehouse_models.py
@@ -12,8 +12,8 @@ from django.db import migrations, models
import posthog.models.utils
import posthog.helpers.encrypted_fields
-import products.data_modeling.backend.models.modeling
-import products.data_modeling.backend.models.datawarehouse_saved_query
+import products.data_modeling.backend.facade.models
+import products.data_modeling.backend.facade.modeling
class Migration(migrations.Migration):
@@ -100,9 +100,7 @@ class Migration(migrations.Migration):
"name",
models.CharField(
max_length=128,
- validators=[
- products.data_modeling.backend.models.datawarehouse_saved_query.validate_saved_query_name
- ],
+ validators=[products.data_modeling.backend.facade.models.validate_saved_query_name],
),
),
("latest_error", models.TextField(blank=True, default=None, null=True)),
@@ -659,7 +657,7 @@ class Migration(migrations.Migration):
default=posthog.models.utils.UUIDT, editable=False, primary_key=True, serialize=False
),
),
- ("path", products.data_modeling.backend.models.modeling.LabelTreeField()),
+ ("path", products.data_modeling.backend.facade.modeling.LabelTreeField()),
(
"created_by",
models.ForeignKey(
diff --git a/products/data_warehouse/backend/models/test/test_managed_viewset.py b/products/data_warehouse/backend/models/test/test_managed_viewset.py
index 31614a0b9d38..d8586818bf9f 100644
--- a/products/data_warehouse/backend/models/test/test_managed_viewset.py
+++ b/products/data_warehouse/backend/models/test/test_managed_viewset.py
@@ -5,8 +5,15 @@ from django.db import IntegrityError
from posthog.schema import RevenueAnalyticsEventItem, RevenueCurrencyPropertyConfig
-from products.data_modeling.backend.facade.models import DataWarehouseManagedViewSet, DataWarehouseSavedQuery
-from products.data_modeling.backend.models import DAG, REVENUE_ANALYTICS_DAG_NAME, Edge, Node, NodeType
+from products.data_modeling.backend.facade.models import (
+ DAG,
+ REVENUE_ANALYTICS_DAG_NAME,
+ DataWarehouseManagedViewSet,
+ DataWarehouseSavedQuery,
+ Edge,
+ Node,
+ NodeType,
+)
from products.warehouse_sources.backend.models.credential import DataWarehouseCredential
from products.warehouse_sources.backend.models.external_data_schema import ExternalDataSchema
from products.warehouse_sources.backend.models.external_data_source import ExternalDataSource
diff --git a/products/data_warehouse/backend/tests/api/test_external_data_schema.py b/products/data_warehouse/backend/tests/api/test_external_data_schema.py
index 4149c346809d..22f3604eddd4 100644
--- a/products/data_warehouse/backend/tests/api/test_external_data_schema.py
+++ b/products/data_warehouse/backend/tests/api/test_external_data_schema.py
@@ -24,7 +24,7 @@ from posthog.models.personal_api_key import PersonalAPIKey, hash_key_value
from posthog.models.utils import generate_random_token_personal
from posthog.temporal.common.schedule import describe_schedule
-from products.data_modeling.backend.models import Edge, Node
+from products.data_modeling.backend.facade.models import Edge, Node
from products.data_warehouse.backend.direct_postgres import DIRECT_POSTGRES_URL_PATTERN
from products.data_warehouse.backend.direct_snowflake import DIRECT_SNOWFLAKE_URL_PATTERN
from products.data_warehouse.backend.logic.external_data_source.webhooks import WebhookHogFunctionCreateResult
diff --git a/pyproject.toml b/pyproject.toml
index 170af7083d29..6a3288fcfc73 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -509,7 +509,6 @@ ignore_imports = [
# Allowed: presentation can import facade and itself
"products.**.backend.presentation.** -> products.**.backend.facade.**",
"products.**.backend.presentation.** -> products.**.backend.presentation.**",
- # data_modeling — presentation wave deferred (views routed through the facade in a follow-up)
# TODO: existing violations — fix by routing through facade
"products.agent_platform.backend.presentation.serializers -> products.agent_platform.backend.models",
"products.agent_platform.backend.presentation.views -> products.agent_platform.backend.db",
diff --git a/tach.toml b/tach.toml
index 4086301b62b7..c2556fd0a663 100644
--- a/tach.toml
+++ b/tach.toml
@@ -830,19 +830,6 @@ from = [
"products.warehouse_sources",
]
-# data_modeling — facade landed; external consumers route through backend.facade.* now.
-# This leak exposes its models only to frozen Django migrations (core + the data_warehouse
-# model-migration) that reference the historical model classes directly and cannot route
-# through a facade. Permanent (migrations are immutable), so backend:contract-check stays off.
-[[interfaces]]
-expose = [
- "backend\\.models.*",
-]
-from = [
- "products.data_modeling",
-]
-
-
# legal_documents has a non-standard public surface — posthog/urls registers its pandadoc
# webhook (presentation.webhook), not the canonical presentation.views — so it gets a dedicated
# block rather than joining the canonical alternation above.