: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(postgres): keep oversized numeric columns as text instead of crashing sync (#66693)
Tom Owersbdf4dd5c3465
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_pipeline_utils.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_pipeline_utils.pyindex 7cf00318f0ab..b8438c4a8924 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_pipeline_utils.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_pipeline_utils.py@@ -433,13 +433,17 @@ def test_table_from_py_list_decimal_exceeding_max_scale_is_rounded():assert table.column("column").to_pylist() == [decimal.Decimal("1." + "1" * 32), None]-def test_table_from_py_list_decimal_too_large_for_decimal256_raises():- # A value whose integer part can't fit decimal256(76, 32) even after rounding to the max- # scale is genuinely unrepresentable, so the hard ValueError must still surface.- value = decimal.Decimal("9" * 45 + "." + "1" * 40)+def test_table_from_py_list_decimal_too_large_for_decimal256_falls_back_to_string():+ # A value whose integer part can't fit decimal256(76, 32) even after rounding to the max scale+ # is genuinely unrepresentable as a decimal. It must fall back to text rather than crash the+ # sync, mirroring the huge-int fallback. A normal value is mixed in to confirm the whole column+ # stringifies consistently.+ huge = decimal.Decimal("9" * 247)- with pytest.raises(ValueError, match="Cannot build decimal array from values"):- table_from_py_list([{"column": value}])+ table = table_from_py_list([{"column": huge}, {"column": decimal.Decimal("1.5")}, {"column": None}])++ assert table.schema.field("column").type == pa.string()+ assert table.column("column").to_pylist() == [str(huge), "1.5", None]def test_table_from_py_list_normal_int_column_stays_int64():diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/utils.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/utils.pyindex f7cd02a7ae3e..8629e466fdd6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/utils.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/utils.py@@ -921,11 +921,19 @@ def _process_batch(table_data: list[dict], schema: Optional[pa.Schema] = None) -if py_type is decimal.Decimalelse [_convert_to_decimal_or_none(x) for x in all_values])- number_arr = _decimal_array_from_values(decimal_values)- new_field_type = number_arr.type-- py_type = decimal.Decimal- unique_types_in_column = {decimal.Decimal}+ try:+ number_arr = _decimal_array_from_values(decimal_values)+ new_field_type = number_arr.type+ py_type = decimal.Decimal+ unique_types_in_column = {decimal.Decimal}+ except ValueError:+ # A value is too large even for decimal256 (e.g. an unconstrained Postgres+ # `numeric` with more than 76 significant digits) — keep the column as text+ # rather than crash the sync, mirroring the huge-int fallback below.+ number_arr = pa.array([None if v is None else str(v) for v in decimal_values], type=pa.string())+ new_field_type = pa.string()+ py_type = str+ unique_types_in_column = {str}else:raise