: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(data-warehouse): keep google sheets text unquoted in mixed columns (#111998)
Daniel RCc0872d2a7e7b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/google_sheets.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/google_sheets.pyindex 2a3e1fe9dd28..1d731fe1fafe 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/google_sheets.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/google_sheets.py@@ -175,7 +175,17 @@ def _records_from_grid(grid: list[list[str]]) -> list[dict[str, Any]]:# default_blank defaults to "", which turns empty cells into strings and breaks numeric# columns that legitimately have gaps. None lets blank cells import as null instead.- return [dict(zip(column_names, numericise_all(row, default_blank=None))) for row in grid[1:]]+ records = [dict(zip(column_names, numericise_all(row, default_blank=None))) for row in grid[1:]]++ # A column that holds both numbers and text must stay text. The pipeline JSON-encodes a column+ # of mixed Python types, which stores each text cell wrapped in double quotes.+ for index, name in enumerate(column_names):+ if len({isinstance(record[name], str) for record in records if record.get(name) is not None}) > 1:+ for raw_row, record in zip(grid[1:], records):+ if name in record:+ record[name] = raw_row[index] or None++ return records# Google's frontend returns this stable "That's an error" doodle page — an HTML body, not the JSONdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/tests/test_google_sheets.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/tests/test_google_sheets.pyindex 0db631077eef..b7c75eddab19 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/tests/test_google_sheets.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_sheets/tests/test_google_sheets.py@@ -481,6 +481,20 @@ def test_google_sheets_source_reads_blank_cells_as_null():]+def test_google_sheets_source_keeps_cell_text_in_a_column_mixing_numbers_and_text():+ tables = _read_sheet(+ ["id", "code"],+ [["1", "spring sale"], ["2", "1,200"], ["3", ""], ["4", "42"]],+ )++ assert tables[0].to_pylist() == [+ {"id": 1, "code": "spring sale"},+ {"id": 2, "code": "1,200"},+ {"id": 3, "code": None},+ {"id": 4, "code": "42"},+ ]++@pytest.mark.parametrize("header_row,expected_columns",[