kokhlo commented on code in PR #45180:
URL: https://github.com/apache/superset/pull/45180#discussion_r4259863266


##########
superset/db_engine_specs/duckdb.py:
##########
@@ -327,6 +327,18 @@ def convert_dttm(
             return f"""'{dttm.isoformat(sep=" ", timespec="microseconds")}'"""
         return None
 
+    @classmethod
+    def register_engine_events(cls, engine: sa.Engine) -> None:
+        # duckdb-engine subclasses the psycopg2 PostgreSQL dialect, whose
+        # class-level _backslash_escapes default is True. Unlike PostgreSQL,
+        # DuckDB never runs the _set_backslash_escapes probe (there is no
+        # standard_conforming_strings knob), so every literal compiled with
+        # literal_binds doubles its backslashes: a filter value like
+        # name\email is rendered as 'name\\email', which DuckDB reads as a
+        # literal double backslash and the query silently matches zero rows.
+        # DuckDB has no escape character at all, so the flag is simply wrong.
+        engine.dialect._backslash_escapes = False

Review Comment:
   Confirmed — reproduced it before touching anything: 
`WhereInMacro(DuckDBDialect())([r"C:\Users"])` rendered `('C:\\Users')` on the 
PR head, while a fresh postgresql dialect came out correct.
   
   Fixed in b7228e5317 by taking the "here" option: 
`_normalize_postgresql_backslash_escapes` now also matches `dialect.name == 
"duckdb"` (with the why in its docstring — inherited psycopg2 flag, no 
`standard_conforming_strings` probe to ever correct it). That covers both 
`where_in` and the `_escape_value` path in `ExtraCache`, since both go through 
that normalizer before compiling against the fresh dialect.
   
   Regression tests added on both paths — `where_in` and 
`ExtraCache._escape_value` against a fresh `duckdb_engine.Dialect()` — and all 
three fail on the previous commit, pass on the new one. Full 
`jinja_context_test.py` + duckdb spec suites green.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to