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.

feat(events): Add person_id to all destinations (#103088)

Tomás Farías Santana550c51355c76
diff --git a/products/batch_exports/backend/temporal/batch_exports.py b/products/batch_exports/backend/temporal/batch_exports.py
index e35e68dc164a..4b53d5ee7ca7 100644
--- a/products/batch_exports/backend/temporal/batch_exports.py
+++ b/products/batch_exports/backend/temporal/batch_exports.py
@@ -164,6 +164,7 @@ def default_fields() -> list[BatchExportField]:
alias="set_once",
),
BatchExportField(expression="person_properties", alias="person_properties"),
+ BatchExportField(expression="person_id", alias="person_id"),
]
@@ -182,6 +183,7 @@ def events_model_default_fields() -> list[BatchExportField]:
BatchExportField(expression="properties", alias="properties"),
BatchExportField(expression="distinct_id", alias="distinct_id"),
BatchExportField(expression="person_properties", alias="person_properties"),
+ BatchExportField(expression="person_id", alias="person_id"),
]
diff --git a/products/batch_exports/backend/temporal/destinations/databricks_batch_export.py b/products/batch_exports/backend/temporal/destinations/databricks_batch_export.py
index 0a2e2669d1b2..10f06c6b747d 100644
--- a/products/batch_exports/backend/temporal/destinations/databricks_batch_export.py
+++ b/products/batch_exports/backend/temporal/destinations/databricks_batch_export.py
@@ -1020,6 +1020,7 @@ def _events_table_fields(json_type: str) -> list[DatabricksField]:
("event", "STRING"),
("properties", json_type),
("person_properties", json_type),
+ ("person_id", "STRING"),
("distinct_id", "STRING"),
("team_id", "BIGINT"),
("timestamp", "TIMESTAMP"),
diff --git a/products/batch_exports/backend/temporal/destinations/postgres_batch_export.py b/products/batch_exports/backend/temporal/destinations/postgres_batch_export.py
index 34107bfb2597..c9bb8d077753 100644
--- a/products/batch_exports/backend/temporal/destinations/postgres_batch_export.py
+++ b/products/batch_exports/backend/temporal/destinations/postgres_batch_export.py
@@ -799,7 +799,7 @@ def _get_table_fields(
) -> Fields:
"""Extract table field definitions from model and schema."""
if model is None or (isinstance(model, BatchExportModel) and model.name == "events"):
- return [
+ table_fields: Fields = [
("uuid", "VARCHAR(200)"),
("event", "VARCHAR(200)"),
("properties", "JSONB"),
@@ -812,7 +812,10 @@ def _get_table_fields(
("site_url", "VARCHAR(200)"),
("timestamp", "TIMESTAMP WITH TIME ZONE"),
("person_properties", "JSONB"),
+ ("person_id", "VARCHAR(200)"),
]
+ # A retry can consume files staged before a new default column was added.
+ return [field for field in table_fields if field[0] in record_batch_schema.names]
else:
return get_postgres_fields_from_record_schema(
record_batch_schema,
@@ -971,9 +974,18 @@ async def insert_into_postgres_activity_from_stage(inputs: PostgresInsertInputs)
f"No matching columns found in the destination table '{inputs.schema}.{inputs.table_name}'"
)
except psycopg.errors.InsufficientPrivilege:
+ if model is None or (
+ isinstance(model, BatchExportModel) and model.name == "events" and model.schema is None
+ ):
+ # Without introspection, do not require this column on older destination tables.
+ table_fields = [field for field in table_fields if field[0] != "person_id"]
+ external_logger.warning(
+ "Skipping person_id because the destination columns could not be inspected. "
+ "Grant SELECT permissions on the destination table to export person_id when the column exists."
+ )
external_logger.warning(
"Insufficient privileges to get table columns for table '%s.%s'; "
- "will assume all columns are present. If this results in an error, please grant SELECT "
+ "will assume all remaining columns are present. If this results in an error, please grant SELECT "
"permissions on this table or ensure the destination table is using the latest schema "
"as described in the docs: https://posthog.com/docs/cdp/batch-exports/postgres",
inputs.schema,
diff --git a/products/batch_exports/backend/temporal/destinations/redshift_batch_export.py b/products/batch_exports/backend/temporal/destinations/redshift_batch_export.py
index 571915bb161e..3adc29d4fd39 100644
--- a/products/batch_exports/backend/temporal/destinations/redshift_batch_export.py
+++ b/products/batch_exports/backend/temporal/destinations/redshift_batch_export.py
@@ -835,7 +835,10 @@ def _get_table_schemas(
("site_url", "VARCHAR(200)"),
("timestamp", "TIMESTAMP WITH TIME ZONE"),
("person_properties", properties_type),
+ ("person_id", "VARCHAR(200)"),
]
+ # A retry can consume files staged before a new default column was added.
+ table_schema = [field for field in table_schema if field[0] in record_batch_schema.names]
else:
table_schema = get_redshift_fields_from_record_schema(
diff --git a/products/batch_exports/backend/temporal/destinations/s3_batch_export.py b/products/batch_exports/backend/temporal/destinations/s3_batch_export.py
index 0432bcc5f791..2e32da75e4eb 100644
--- a/products/batch_exports/backend/temporal/destinations/s3_batch_export.py
+++ b/products/batch_exports/backend/temporal/destinations/s3_batch_export.py
@@ -288,7 +288,7 @@ def s3_default_fields() -> list[BatchExportField]:
Starting from the common default fields, we add and tweak some fields for
backwards compatibility.
"""
- batch_export_fields = default_fields()
+ batch_export_fields = [field for field in default_fields() if field["alias"] != "person_id"]
batch_export_fields.append({"expression": "elements_chain", "alias": "elements_chain"})
batch_export_fields.append({"expression": "person_id", "alias": "person_id"})
diff --git a/products/batch_exports/backend/tests/temporal/destinations/azure_blob/utils.py b/products/batch_exports/backend/tests/temporal/destinations/azure_blob/utils.py
index acc35c5d8b3e..c569521cf499 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/azure_blob/utils.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/azure_blob/utils.py
@@ -217,6 +217,9 @@ async def assert_clickhouse_records_in_azure_blob(
expected_columns = list(expected_records[0].keys())
+ if model_name == "events" and fields is None:
+ assert "person_id" in expected_columns
+
if "team_id" in expected_columns:
assert all(record.get("team_id") == team_id for record in exported_records), (
f"Some exported records have wrong team_id (expected {team_id})"
diff --git a/products/batch_exports/backend/tests/temporal/destinations/bigquery/utils.py b/products/batch_exports/backend/tests/temporal/destinations/bigquery/utils.py
index aac89b9bc2b3..ca9a0a9174b1 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/bigquery/utils.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/bigquery/utils.py
@@ -221,6 +221,9 @@ async def assert_clickhouse_records_in_bigquery(
assert len(inserted_records) == len(expected_records)
+ if model_name == "events" and fields is None and expected_fields is None:
+ assert "person_id" in inserted_records[0]
+
# Ordering is not guaranteed, so we sort before comparing.
inserted_records.sort(key=operator.itemgetter(sort_key))
expected_records.sort(key=operator.itemgetter(sort_key))
diff --git a/products/batch_exports/backend/tests/temporal/destinations/databricks/test_utils.py b/products/batch_exports/backend/tests/temporal/destinations/databricks/test_utils.py
index cbf6d39e389f..e446e4f66ee2 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/databricks/test_utils.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/databricks/test_utils.py
@@ -51,15 +51,17 @@ def test_events_table_fields_match_the_exported_fields():
# `_inserted_at` only tracks progress and is never exported.
exported = sorted(field["alias"] for field in databricks_default_fields() if field["alias"] != "_inserted_at")
+ assert "person_id" in exported
assert sorted(name for name, _ in _events_table_fields("VARIANT")) == exported
-def test_events_table_fields_drop_columns_missing_from_staged_data():
- # A run that staged its data before `created_at` was added has no such column to copy, so
[email protected]("missing_column", ["created_at", "person_id"])
+def test_events_table_fields_drop_columns_missing_from_staged_data(missing_column: str) -> None:
+ # A run that staged its data before a column was added has no such column to copy, so
# dropping it keeps the copy working instead of wedging the run on a retry loop.
- staged = [field["alias"] for field in databricks_default_fields() if field["alias"] != "created_at"]
+ staged = [field["alias"] for field in databricks_default_fields() if field["alias"] != missing_column]
- assert "created_at" not in _events_table_field_names(staged, schema=None)
+ assert missing_column not in _events_table_field_names(staged, schema=None)
def test_events_table_fields_follow_a_custom_schema():
diff --git a/products/batch_exports/backend/tests/temporal/destinations/databricks/test_workflow.py b/products/batch_exports/backend/tests/temporal/destinations/databricks/test_workflow.py
index cc6051fa3841..fd0d3a49c2f5 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/databricks/test_workflow.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/databricks/test_workflow.py
@@ -383,6 +383,7 @@ class TestDatabricksBatchExportWorkflow(CommonWorkflowTests):
("event", "STRING"),
("properties", "VARIANT"),
("distinct_id", "STRING"),
+ ("person_id", "STRING"),
("team_id", "BIGINT"),
("timestamp", "TIMESTAMP"),
("created_at", "TIMESTAMP"),
diff --git a/products/batch_exports/backend/tests/temporal/destinations/postgres/conftest.py b/products/batch_exports/backend/tests/temporal/destinations/postgres/conftest.py
index 3bd73d7a820d..ad01beb44983 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/postgres/conftest.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/postgres/conftest.py
@@ -1,9 +1,13 @@
+import uuid
+from collections.abc import AsyncIterator
+
import pytest
from django.conf import settings
import psycopg
import pytest_asyncio
+from psycopg import sql
from posthog.models import Integration
@@ -38,6 +42,31 @@ async def postgres_connection(postgres_config, setup_postgres_test_db):
await connection.close()
+@pytest_asyncio.fixture
+async def insert_only_postgres_config(
+ request: pytest.FixtureRequest, postgres_connection: psycopg.AsyncConnection, postgres_config: dict[str, str | int]
+) -> AsyncIterator[dict[str, str | int]]:
+ if not request.param:
+ yield postgres_config
+ return
+
+ role_name = f"batch_export_insert_only_{uuid.uuid4().hex}"
+ role = sql.Identifier(role_name)
+ password = uuid.uuid4().hex
+ async with postgres_connection.cursor() as cursor:
+ await cursor.execute(sql.SQL("CREATE ROLE {} LOGIN PASSWORD {}").format(role, sql.Literal(password)))
+ try:
+ await cursor.execute(
+ sql.SQL("GRANT USAGE, CREATE ON SCHEMA {} TO {}").format(
+ sql.Identifier(str(postgres_config["schema"])), role
+ )
+ )
+ yield {**postgres_config, "user": role_name, "password": password}
+ finally:
+ await cursor.execute(sql.SQL("DROP OWNED BY {}").format(role))
+ await cursor.execute(sql.SQL("DROP ROLE {}").format(role))
+
+
@pytest.fixture
def test_properties(request, session_id):
"""Include some problematic properties."""
diff --git a/products/batch_exports/backend/tests/temporal/destinations/postgres/test_activity.py b/products/batch_exports/backend/tests/temporal/destinations/postgres/test_activity.py
index 652f00ed9f51..0e7915289ebd 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/postgres/test_activity.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/postgres/test_activity.py
@@ -9,7 +9,7 @@ from django.test import override_settings
import pytest_asyncio
from psycopg import sql
-from products.batch_exports.backend.service import BatchExportModel, BatchExportSchema
+from products.batch_exports.backend.service import BatchExportField, BatchExportModel, BatchExportSchema
from products.batch_exports.backend.temporal.destinations.postgres_batch_export import (
PostgresInsertInputs,
insert_into_postgres_activity_from_stage,
@@ -20,6 +20,7 @@ from products.batch_exports.backend.temporal.pipeline.internal_stage import (
insert_into_internal_stage_activity,
)
from products.batch_exports.backend.tests.temporal.destinations.postgres.utils import (
+ EXPECTED_EVENTS_BATCH_EXPORT_FIELDS,
EXPECTED_PERSONS_BATCH_EXPORT_FIELDS,
TEST_MODELS,
assert_clickhouse_records_in_postgres,
@@ -52,6 +53,7 @@ async def _run_activity(
expected_fields=None,
expect_duplicates: bool = False,
integration_id: int | None = None,
+ destination_default_fields: list[BatchExportField] | None = None,
):
"""Helper function to run Postgres main activity and assert records are exported."""
if integration_id is not None:
@@ -91,7 +93,9 @@ async def _run_activity(
backfill_details=None,
batch_export_model=insert_inputs.batch_export_model,
batch_export_schema=insert_inputs.batch_export_schema,
- destination_default_fields=postgres_default_fields(),
+ destination_default_fields=(
+ postgres_default_fields() if destination_default_fields is None else destination_default_fields
+ ),
),
)
insert_inputs.stage_folder = stage_result.stage_folder
@@ -116,6 +120,130 @@ async def _run_activity(
return result
[email protected]("model", [None, BatchExportModel(name="events", schema=None)])
+async def test_insert_into_postgres_activity_handles_old_staged_events(
+ clickhouse_client,
+ activity_environment,
+ postgres_connection,
+ postgres_config,
+ model: BatchExportModel | None,
+ generate_test_data,
+ data_interval_start,
+ data_interval_end,
+ ateam,
+) -> None:
+ result = await _run_activity(
+ activity_environment=activity_environment,
+ postgres_connection=postgres_connection,
+ clickhouse_client=clickhouse_client,
+ postgres_config=postgres_config,
+ team=ateam,
+ data_interval_start=data_interval_start,
+ data_interval_end=data_interval_end,
+ table_name="old_staged_events",
+ batch_export_model=model,
+ destination_default_fields=[field for field in postgres_default_fields() if field["alias"] != "person_id"],
+ expected_fields=[field for field in EXPECTED_EVENTS_BATCH_EXPORT_FIELDS if field != "person_id"],
+ )
+ assert result.error is None
+ assert result.records_completed > 0
+
+
+ "model, insert_only_postgres_config",
+ [
+ pytest.param(None, False, id="existing-events-table"),
+ pytest.param(None, True, id="default-without-select"),
+ pytest.param(BatchExportModel(name="events", schema=None), True, id="events-without-select"),
+ pytest.param(
+ BatchExportModel(
+ name="events",
+ schema={"fields": [{"expression": "person_id", "alias": "person_id"}], "values": {}},
+ ),
+ True,
+ id="custom-events-without-select",
+ ),
+ pytest.param(
+ {"fields": [{"expression": "person_id", "alias": "person_id"}], "values": {}},
+ True,
+ id="custom-schema-without-select",
+ ),
+ ],
+ indirect=["insert_only_postgres_config"],
+)
+async def test_insert_into_postgres_activity_handles_existing_events_table(
+ clickhouse_client,
+ activity_environment,
+ postgres_connection,
+ postgres_config,
+ insert_only_postgres_config,
+ model: BatchExportModel | BatchExportSchema | None,
+ generate_test_data,
+ data_interval_start,
+ data_interval_end,
+ ateam,
+) -> None:
+ table_name = "existing_events"
+ batch_export_model = model if isinstance(model, BatchExportModel) else None
+ batch_export_schema = model if isinstance(model, dict) else None
+ custom_schema = batch_export_schema or (batch_export_model.schema if batch_export_model else None)
+
+ await _run_activity(
+ activity_environment=activity_environment,
+ postgres_connection=postgres_connection,
+ clickhouse_client=clickhouse_client,
+ postgres_config=postgres_config,
+ team=ateam,
+ data_interval_start=data_interval_start,
+ data_interval_end=data_interval_end,
+ table_name=table_name,
+ batch_export_model=batch_export_model,
+ batch_export_schema=batch_export_schema,
+ sort_key="person_id" if custom_schema is not None else "event",
+ )
+
+ table = sql.Identifier(postgres_config["schema"], table_name)
+ async with postgres_connection.cursor() as cursor:
+ await cursor.execute(sql.SQL("TRUNCATE TABLE {}").format(table))
+ if custom_schema is None:
+ await cursor.execute(sql.SQL("ALTER TABLE {} DROP COLUMN person_id").format(table))
+ if insert_only_postgres_config != postgres_config:
+ await cursor.execute(
+ sql.SQL("GRANT INSERT ON {} TO {}").format(table, sql.Identifier(insert_only_postgres_config["user"]))
+ )
+ await cursor.execute(
+ "SELECT has_table_privilege(%s, %s, 'SELECT'), has_table_privilege(%s, %s, 'INSERT')",
+ (
+ insert_only_postgres_config["user"],
+ table.as_string(postgres_connection),
+ insert_only_postgres_config["user"],
+ table.as_string(postgres_connection),
+ ),
+ )
+ assert await cursor.fetchone() == (False, True)
+
+ result = await _run_activity(
+ activity_environment=activity_environment,
+ postgres_connection=postgres_connection,
+ clickhouse_client=clickhouse_client,
+ postgres_config=insert_only_postgres_config,
+ team=ateam,
+ data_interval_start=data_interval_start,
+ data_interval_end=data_interval_end,
+ table_name=table_name,
+ batch_export_model=batch_export_model,
+ batch_export_schema=batch_export_schema,
+ expected_fields=(
+ ["person_id"]
+ if custom_schema is not None
+ else [field for field in EXPECTED_EVENTS_BATCH_EXPORT_FIELDS if field != "person_id"]
+ ),
+ sort_key="person_id" if custom_schema is not None else "event",
+ )
+ assert result.error is None
+ assert result.records_completed > 0
+
+
@pytest.mark.parametrize("exclude_events", [None, ["test-exclude"]], indirect=True)
@pytest.mark.parametrize("model", TEST_MODELS)
@pytest.mark.parametrize("integration", [True, False], indirect=True)
diff --git a/products/batch_exports/backend/tests/temporal/destinations/postgres/utils.py b/products/batch_exports/backend/tests/temporal/destinations/postgres/utils.py
index e2af6c856752..c7f21ce5f01b 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/postgres/utils.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/postgres/utils.py
@@ -19,6 +19,22 @@ from products.batch_exports.backend.tests.temporal.utils.records import (
remove_duplicates_from_records,
)
+EXPECTED_EVENTS_BATCH_EXPORT_FIELDS = [
+ "uuid",
+ "event",
+ "properties",
+ "elements",
+ "set",
+ "set_once",
+ "distinct_id",
+ "team_id",
+ "ip",
+ "site_url",
+ "timestamp",
+ "person_properties",
+ "person_id",
+]
+
EXPECTED_PERSONS_BATCH_EXPORT_FIELDS = [
"team_id",
"distinct_id",
@@ -134,6 +150,9 @@ async def assert_clickhouse_records_in_postgres(
fields = None
filters = None
+ if model_name == "events" and fields is None and expected_fields is None:
+ expected_fields = EXPECTED_EVENTS_BATCH_EXPORT_FIELDS
+
expected_records = []
queue = RecordBatchQueue()
if model_name == "sessions":
diff --git a/products/batch_exports/backend/tests/temporal/destinations/redshift/test_activity.py b/products/batch_exports/backend/tests/temporal/destinations/redshift/test_activity.py
index f93fae20917b..bd1fda70dd82 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/redshift/test_activity.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/redshift/test_activity.py
@@ -529,6 +529,7 @@ async def test_insert_into_redshift_activity_handles_person_schema_changes(
@pytest.mark.parametrize("exclude_events", [None], indirect=True)
@pytest.mark.parametrize("properties_data_type", ["super"], indirect=True)
@pytest.mark.parametrize("model", [TEST_MODELS[1]])
[email protected]("missing_person_id", [False, True])
async def test_insert_into_redshift_activity_inserts_data_with_extra_columns(
clickhouse_client,
activity_environment,
@@ -541,6 +542,7 @@ async def test_insert_into_redshift_activity_inserts_data_with_extra_columns(
data_interval_end,
properties_data_type,
ateam,
+ missing_person_id: bool,
):
"""Test data is inserted even in the presence of additional columns.
@@ -577,6 +579,12 @@ async def test_insert_into_redshift_activity_inserts_data_with_extra_columns(
sql.Identifier(redshift_config["schema"], table_name)
)
)
+ if missing_person_id:
+ await cursor.execute(
+ sql.SQL("ALTER TABLE {} DROP COLUMN person_id").format(
+ sql.Identifier(redshift_config["schema"], table_name)
+ )
+ )
await _run_activity(
activity_environment,
@@ -592,4 +600,7 @@ async def test_insert_into_redshift_activity_inserts_data_with_extra_columns(
redshift_config=redshift_config,
sort_key=sort_key,
extra_fields=["test"],
+ expected_fields=[field["alias"] for field in redshift_default_fields() if field["alias"] != "person_id"]
+ if missing_person_id
+ else None,
)
diff --git a/products/batch_exports/backend/tests/temporal/destinations/redshift/test_redshift_utils.py b/products/batch_exports/backend/tests/temporal/destinations/redshift/test_redshift_utils.py
index 118eebc389ab..4db30cd2507f 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/redshift/test_redshift_utils.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/redshift/test_redshift_utils.py
@@ -8,13 +8,14 @@ from unittest import mock
from django.conf import settings
import psycopg
+import pyarrow as pa
import aioboto3
import pytest_asyncio
import botocore.exceptions
from posthog.models.integration import AWSRedshiftRoleBasedIntegration, Integration, IntegrationError
-from products.batch_exports.backend.service import AWSCredentials
+from products.batch_exports.backend.service import AWSCredentials, BatchExportModel
from products.batch_exports.backend.temporal.destinations.redshift_batch_export import (
ClientErrorGroup,
InsufficientS3PermissionsError,
@@ -22,6 +23,7 @@ from products.batch_exports.backend.temporal.destinations.redshift_batch_export
RedshiftS3CopyError,
ServerlessWorkgroup,
_get_redshift_credentials_policy_statements,
+ _get_table_schemas,
_parse_redshift_host,
check_and_raise_redshift_copy_error,
is_s3_read_access_denied,
@@ -33,6 +35,22 @@ from products.batch_exports.backend.tests.temporal.utils.s3 import delete_all_fr
TEST_ROOT_BUCKET = "test-batch-exports"
[email protected]("has_person_id", [False, True])
[email protected]("properties_data_type", ["varchar", "super"])
+def test_events_table_schemas_match_staged_person_id(has_person_id: bool, properties_data_type: str) -> None:
+ columns = ["uuid", "properties"]
+ if has_person_id:
+ columns.append("person_id")
+ schema = pa.schema([(name, pa.string()) for name in columns])
+
+ table_schemas = _get_table_schemas(BatchExportModel(name="events", schema=None), schema, properties_data_type)
+
+ for fields in (table_schemas.table_schema, table_schemas.stage_table_schema):
+ assert {name for name, _ in fields} == set(columns)
+ if has_person_id:
+ assert dict(fields)["person_id"] == "VARCHAR(200)"
+
+
@pytest.mark.parametrize(
"value,expected",
[
diff --git a/products/batch_exports/backend/tests/temporal/destinations/snowflake/utils.py b/products/batch_exports/backend/tests/temporal/destinations/snowflake/utils.py
index 68a306f162cb..5d3a96a94262 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/snowflake/utils.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/snowflake/utils.py
@@ -511,6 +511,9 @@ async def assert_clickhouse_records_in_snowflake(
inserted_records = remove_duplicates_from_records(inserted_records, primary_key)
assert inserted_records, "No records were inserted into Snowflake"
+ if model_name == "events" and fields is None and expected_fields is None:
+ assert "person_id" in inserted_records[0]
+
inserted_column_names = list(inserted_records[0].keys())
expected_column_names = list(expected_records[0].keys())
inserted_column_names.sort()
diff --git a/products/batch_exports/backend/tests/temporal/pipeline/test_internal_stage.py b/products/batch_exports/backend/tests/temporal/pipeline/test_internal_stage.py
index cb9350689c05..87b5a60d96ac 100644
--- a/products/batch_exports/backend/tests/temporal/pipeline/test_internal_stage.py
+++ b/products/batch_exports/backend/tests/temporal/pipeline/test_internal_stage.py
@@ -319,11 +319,6 @@ async def test_insert_into_stage_activity_for_events_model(
exclude_events,
truncate_clickhouse_tables,
):
- """Test that the insert_into_internal_stage_activity produces expected data in the internal stage.
-
- For now we just check that the number of records exported is correct, not the content of the records.
- """
-
records_exported = await _run_activity(
activity_environment=activity_environment,
object_storage_client=object_storage_client,
@@ -337,6 +332,9 @@ async def test_insert_into_stage_activity_for_events_model(
events_to_export_created = generate_test_data[0]
assert len(records_exported) == len(events_to_export_created)
+ assert {record["uuid"]: record["person_id"] for record in records_exported} == {
+ event["uuid"]: event["person_id"] for event in events_to_export_created
+ }
@pytest.mark.parametrize("interval", ["day"], indirect=True)
diff --git a/products/batch_exports/backend/tests/temporal/test_batch_exports.py b/products/batch_exports/backend/tests/temporal/test_batch_exports.py
index 3d51e75c454f..6f8eb359b3a6 100644
--- a/products/batch_exports/backend/tests/temporal/test_batch_exports.py
+++ b/products/batch_exports/backend/tests/temporal/test_batch_exports.py
@@ -84,6 +84,9 @@ async def test_iter_records(clickhouse_client, use_native_schema, interval_minut
]
assert_records_match_events(records, events)
+ assert {record["uuid"]: record["person_id"] for record in records} == {
+ event["uuid"]: event["person_id"] for event in events
+ }
async def test_iter_records_handles_duplicates(clickhouse_client):