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(telnyx): fall back to id primary key for messages missing uuid (#88969)

Tom Owersbb6b1f51d796
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_writer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_writer.py
index ebc14b744ec7..bce6c4bde17e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_writer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_writer.py
@@ -415,6 +415,41 @@ class TestLegacyDltTableReconciliation:
primary_keys=["id"],
)
+ @pytest.mark.asyncio
+ async def test_incremental_merge_uses_fallback_key_when_primary_missing_from_batch(self, tmp_path: Path) -> None:
+ """Some sources emit rows in more than one shape for the same table (e.g. a record
+ sub-type that carries no `uuid`, only `id`). Configuring more than one primary key
+ candidate must let a batch merge on whichever one it actually has, instead of raising
+ MissingPrimaryKeysException just because the first-listed key is absent from this batch."""
+ delta_path = str(tmp_path / "table")
+ deltalake.write_deltalake(
+ delta_path,
+ pa.table(
+ {"uuid": ["u1"], "id": [None], "name": ["a"]},
+ schema=pa.schema(
+ [
+ pa.field("uuid", pa.string()),
+ pa.field("id", pa.string()),
+ pa.field("name", pa.string()),
+ ]
+ ),
+ ),
+ )
+
+ helper = make_local_table_ref(delta_path)
+ batch = pa.table({"id": ["2"], "name": ["b"]})
+
+ result = await DeltaWriter(helper).write(
+ data=batch,
+ write_type="incremental",
+ should_overwrite_table=False,
+ primary_keys=["uuid", "id"],
+ )
+
+ final = result.to_pyarrow_table()
+ assert final.num_rows == 2
+ assert set(final.column("name").to_pylist()) == {"a", "b"}
+
class TestAppendDecimalReconciliation:
"""Appending a decimal column that outgrew decimal128 must reconcile to the stored type.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/telnyx/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/telnyx/canonical_descriptions.py
index 89ff6c57c564..5a0abb958d26 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/telnyx/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/telnyx/canonical_descriptions.py
@@ -9,7 +9,8 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"description": "Per-message detail records (MDRs) for SMS/MMS sent or received through Telnyx Messaging.",
"docs_url": DETAIL_RECORD_SEARCH_DOCS_URL,
"columns": {
- "uuid": "Unique identifier of the message.",
+ "uuid": "Unique identifier of the message. Not present on RCS messages; use `id` for those.",
+ "id": "Unique identifier of the message, used for RCS messages instead of `uuid`.",
"user_id": "Identifier of the Telnyx account who owns the message.",
"completed_at": "Message completion time.",
"created_at": "Message creation time.",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/telnyx/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/telnyx/settings.py
index 43df357d4f2b..00cd2b92aaab 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/telnyx/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/telnyx/settings.py
@@ -31,7 +31,12 @@ TELNYX_ENDPOINTS: dict[str, TelnyxEndpoint] = {
name="MessagingDetailRecords",
table_name="messaging_detail_records",
record_type="messaging",
- primary_key=["uuid"],
+ # SMS/MMS records carry `uuid`, but RCS records (`agent_name`/`product_name` present
+ # instead) carry no `uuid` field at all, only `id`. The writer already merges on
+ # whichever configured key survives into a given batch, so listing both lets each
+ # record shape merge on its own identifier instead of failing incremental syncs on tables
+ # that mix RCS in with SMS/MMS.
+ primary_key=["uuid", "id"],
partition_key="created_at",
incremental_field="created_at",
),