: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(mysql): allow # in quoted MySQL identifiers (#130537)
Tom Owersce6ff4b202ae
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/identifiers.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/identifiers.pyindex 3eac75f3e1a4..8630191b718c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/identifiers.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/identifiers.py@@ -34,17 +34,21 @@ class InvalidIdentifierError(ValueError):"""-_ALLOWED_EXTRA_CHARS = set("._-$@")+_ALLOWED_EXTRA_CHARS = set("._-$@#")_ALL_DIGITS = re.compile(r"^\d+$")def _validate_identifier(identifier: str) -> None:"""Allowlist check shared by every concrete quoter.- Accepts: alphanumeric plus `.`, `_`, `-`, `$`, `@`. An identifier that- is nothing but digits is also allowed (matches today's MySQL behavior- where `"851"` is quoted verbatim). Anything else — whitespace, a- semicolon, a quote character, a NUL byte — raises.+ Accepts: alphanumeric plus `.`, `_`, `-`, `$`, `@`, `#`. An identifier+ that is nothing but digits is also allowed (matches today's MySQL+ behavior where `"851"` is quoted verbatim). `#` is allowed because+ Tableau's MySQL driver creates (and sometimes leaves behind) temp+ tables named `#Tableau_<pid>_<sid>_Connect_CheckCreateTempTableCap`+ when it tests a connection; always wrapped in backticks, it's never+ parsed as MySQL's `#`-starts-a-comment syntax. Anything else —+ whitespace, a semicolon, a quote character, a NUL byte — raises."""if not identifier:raise InvalidIdentifierError("Identifier may not be empty")diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_identifiers.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_identifiers.pyindex ab04b945fd61..060232030d78 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_identifiers.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_identifiers.py@@ -23,6 +23,12 @@ class TestBacktickIdentifierQuoter:("db@prod", "`db@prod`"),("a-b", "`a-b`"),("a.b", "`a.b`"),+ # A real Tableau MySQL-driver temp table name, created (and sometimes left+ # behind) when it tests a connection's ability to create temp tables.+ (+ "#Tableau_8_sid_00130535_3_Connect_CheckCreateTempTableCap",+ "`#Tableau_8_sid_00130535_3_Connect_CheckCreateTempTableCap`",+ ),],)def test_accepts_allowed_identifiers(self, identifier: str, expected: str) -> None: