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(mysql): treat unknown-column (1054) errors as non-retryable (#63980)

Tom Owers4521fe0d90fd
diff --git a/posthog/temporal/data_imports/sources/mysql/source.py b/posthog/temporal/data_imports/sources/mysql/source.py
index 5618d79da901..14ce71ae9370 100644
--- a/posthog/temporal/data_imports/sources/mysql/source.py
+++ b/posthog/temporal/data_imports/sources/mysql/source.py
@@ -146,6 +146,15 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabase
# existing column in place, so retrying won't help — the table must be reset and
# fully re-synced to adopt the new type.
"Source column type changed": "A column's type changed in your source database (for example an integer column was widened to bigint) and no longer fits the type we stored. We can't widen an existing column in place — please reset and fully re-sync this table to adopt the new type.",
+ # MySQL/MariaDB error 1054 (ER_BAD_FIELD_ERROR): a column the sync query references no
+ # longer exists in the source table — almost always the configured incremental field
+ # after the column was renamed or dropped (schema drift). The streaming query reissues
+ # the same WHERE/ORDER BY on every attempt, so it fails identically forever; the COUNT(*)
+ # probe already swallows this same error expecting it to be classified here. Match on the
+ # locale-independent error code (the column name and clause are volatile, and the message
+ # text is translated on non-English servers) so it catches both the raw pymysql string and
+ # the Temporal-wrapped `OperationalError: (1054, ...)` form.
+ '(1054, "Unknown column': "A column referenced during sync no longer exists in your source table (MySQL error 1054). This usually means a column was renamed or dropped — if it's the table's incremental field, update it to a column that exists (or switch to a full re-sync), then resync.",
}
def validate_credentials(
diff --git a/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py b/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py
index a33b66276638..61ab3800a29c 100644
--- a/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py
+++ b/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py
@@ -854,6 +854,22 @@ class TestMySQLSourceNonRetryableErrors:
is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
assert is_non_retryable, f"Host-blocked error should be non-retryable: {error_msg}"
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ # Raw pymysql str(error) form (classified in `_handle_import_error`).
+ str(pymysql.err.OperationalError(1054, "Unknown column 'favoritor_id' in 'where clause'")),
+ # Temporal-wrapped str(e.cause) form (classified in external_data_job).
+ "OperationalError: (1054, \"Unknown column 'favoritor_id' in 'where clause'\")",
+ # Other clause variants share the same 1054 code and "Unknown column" prefix.
+ "OperationalError: (1054, \"Unknown column 'deleted_at' in 'order clause'\")",
+ ],
+ )
+ def test_unknown_column_is_non_retryable(self, source, error_msg):
+ non_retryable = source.get_non_retryable_errors()
+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
+ assert is_non_retryable, f"Unknown-column error should be non-retryable: {error_msg}"
+
@pytest.mark.parametrize(
"error_msg",
[