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(batch-exports): Handle snowflake invalid types (#64343)

Tomás Farías Santana7427e5853ee3
diff --git a/products/batch_exports/backend/temporal/destinations/snowflake_batch_export.py b/products/batch_exports/backend/temporal/destinations/snowflake_batch_export.py
index 1c5e16411127..bc0c1bd56e5b 100644
--- a/products/batch_exports/backend/temporal/destinations/snowflake_batch_export.py
+++ b/products/batch_exports/backend/temporal/destinations/snowflake_batch_export.py
@@ -807,7 +807,7 @@ class SnowflakeClient:
SnowflakeTableNotFoundError: If the table we are trying to get doesn't exist.
SnowflakeIncompatibleSchemaError: If the table does exist, but it is a
mutable table and one or more fields from the primary key are missing
- from the table.
+ from the table, or the fields we require have types we do not support.
"""
try:
result = await self.execute_async_query(f"""
@@ -854,14 +854,22 @@ class SnowflakeClient:
if field_metadata.name.lower() in record_batch_field_names
)
- return SnowflakeTable.from_snowflake_table(
- table.name,
- fields=fields,
- parents=table.parents,
- primary_key=table.primary_key,
- version_key=table.version_key,
- stage_prefix=table.stage_prefix,
- )
+ try:
+ table = SnowflakeTable.from_snowflake_table(
+ table.name,
+ fields=fields,
+ parents=table.parents,
+ primary_key=table.primary_key,
+ version_key=table.version_key,
+ stage_prefix=table.stage_prefix,
+ )
+ except ValueError as exc:
+ raise SnowflakeIncompatibleSchemaError(
+ f"A Snowflake table '{table.name}' was found, but one or more "
+ f"fields are defined with incompatible types: '{exc}'. Have "
+ "you created the table following the PostHog documentation? "
+ ) from exc
+ return table
async def create_table(self, table: SnowflakeTable, exists_ok: bool = True) -> None:
"""Asynchronously create the table if it doesn't exist.