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.

fix(data-warehouse): match cdp triggers on the linked table name (#108761)

Arthur Moreira de Deus8e4514fd5066
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/cdp_producer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/cdp_producer.py
index 9d6491fc52d6..18bfe1ce893e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/cdp_producer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/cdp_producer.py
@@ -180,8 +180,10 @@ class CDPProducer:
id=self.table.id, team_id=self.team_id
)
- schema = ExternalDataSchema.objects.get(id=self.table.id, team_id=self.team_id)
- raw_table_name = build_table_name(schema.source, schema.name)
+ schema = ExternalDataSchema.objects.select_related("source", "table").get(
+ id=self.table.id, team_id=self.team_id
+ )
+ raw_table_name = schema.table.name if schema.table else build_table_name(schema.source, schema.name)
return get_data_warehouse_table_name(schema.source, raw_table_name)
self._table_name_cache = await _resolve()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_cdp_producer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_cdp_producer.py
index a337845bb29b..5b2df439b69c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_cdp_producer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_cdp_producer.py
@@ -71,24 +71,35 @@ async def test_should_run_no_hog_function(team):
@pytest.mark.django_db(transaction=True)
@pytest.mark.asyncio
-async def test_should_run_with_matching_hog_function(team):
+ ("schema_name", "linked_table_name", "hogql_table_name"),
+ [
+ ("public.widgets", "postgres_widgets", "postgres.widgets"),
+ ("public.widgets", None, "postgres.public__widgets"),
+ ],
+)
+async def test_should_run_with_matching_hog_function(team, schema_name, linked_table_name, hogql_table_name):
source = await sync_to_async(ExternalDataSource.objects.create)(
team=team, source_type=ExternalDataSourceType.POSTGRES
)
- table = await sync_to_async(DataWarehouseTable.objects.create)(
- team=team, name="postgres_table_1", external_data_source=source
+ table = (
+ await sync_to_async(DataWarehouseTable.objects.create)(
+ team=team, name=linked_table_name, external_data_source=source
+ )
+ if linked_table_name
+ else None
)
schema = await sync_to_async(ExternalDataSchema.objects.create)(
- team=team, name="table_1", source=source, table=table
+ team=team, name=schema_name, source=source, table=table
)
-
await sync_to_async(HogFunction.objects.create)(
team=team,
enabled=True,
- filters={"source": "data-warehouse-table", "data_warehouse": [{"table_name": "postgres.table_1"}]},
+ filters={"source": "data-warehouse-table", "data_warehouse": [{"table_name": hogql_table_name}]},
)
producer = CDPProducer.for_source(team_id=team.id, schema_id=str(schema.id), job_id="", logger=mock.AsyncMock())
+ assert await producer.get_dot_notated_table_name() == hogql_table_name
assert await producer.should_run() is True
@@ -146,7 +157,7 @@ async def test_should_run_with_new_style_table_name(team):
team=team, source_type=ExternalDataSourceType.POSTGRES
)
table = await sync_to_async(DataWarehouseTable.objects.create)(
- team=team, name="postgres.table_1", external_data_source=source
+ team=team, name="postgres_table_1", external_data_source=source
)
schema = await sync_to_async(ExternalDataSchema.objects.create)(
team=team, name="table_1", source=source, table=table
@@ -169,7 +180,7 @@ async def test_should_run_with_source_prefix(team):
team=team, source_type=ExternalDataSourceType.POSTGRES, prefix="eu"
)
table = await sync_to_async(DataWarehouseTable.objects.create)(
- team=team, name="postgres_eu_table_1", external_data_source=source
+ team=team, name="eupostgres_table_1", external_data_source=source
)
schema = await sync_to_async(ExternalDataSchema.objects.create)(
team=team, name="table_1", source=source, table=table
@@ -192,7 +203,7 @@ async def test_should_run_with_leading_underscore_source_prefix(team):
team=team, source_type=ExternalDataSourceType.POSTGRES, prefix="_eu"
)
table = await sync_to_async(DataWarehouseTable.objects.create)(
- team=team, name="postgres_eu_table_1", external_data_source=source
+ team=team, name="_eupostgres_table_1", external_data_source=source
)
schema = await sync_to_async(ExternalDataSchema.objects.create)(
team=team, name="table_1", source=source, table=table