Lee-W commented on code in PR #77108:
URL: https://github.com/apache/airflow/pull/77108#discussion_r4597563141


##########
providers/common/ai/tests/unit/common/ai/utils/test_sql_validation.py:
##########
@@ -466,12 +466,17 @@ def test_flags_table_row_source_as_unverifiable(self, 
sql):
         scan = collect_table_references(parse_sql(sql, dialect="snowflake"))
         assert scan.unverifiable_sources
 
-    def test_flags_table_shorthand_as_unverifiable(self):
-        """The TABLE <name> shorthand is mis-parsed by sqlglot, so reject 
it."""
+    def test_table_shorthand_never_hides_its_table(self):
+        """
+        ``TABLE <name>`` must never reach a table unseen.
+
+        sqlglot < 30.31 mis-parses the shorthand, so it is flagged as 
unverifiable; newer
+        sqlglot expands it to ``SELECT * FROM <name>``, so the table is 
reported instead.
+        """
         scan = collect_table_references(
             parse_sql("TABLE secret UNION SELECT * FROM orders", 
dialect="postgres")
         )
-        assert scan.unverifiable_sources
+        assert scan.unverifiable_sources or "secret" in {t for _, _, t in 
scan.tables}

Review Comment:
   Nit: "secret" in {t for _, _, t in scan.tables} also passes when secret 
shows up under another schema. The neighbouring test uses the exact tuple ("", 
"", "secret") in scan.tables; could this match it?



##########
airflow-core/src/airflow/utils/orm_event_handlers.py:
##########
@@ -30,6 +31,33 @@
 log = logging.getLogger(__name__)
 
 
+class _StrSubclassEncoders(dict):
+    """
+    mysqlclient encoder map that binds ``str`` subclasses by their string 
value.
+
+    Since mysqlclient 2.3.1, ``Connection.literal`` only treats exact ``str`` 
as a string and
+    escapes anything else through this map, falling back to ``str(o)`` for 
unknown types. For
+    ``(str, Enum)`` values such as ``TaskInstanceState.FAILED`` that is the 
member name
+    (``"TaskInstanceState.FAILED"``), not the value (``"failed"``).
+    """
+
+    def __init__(self, dbapi_connection):
+        super().__init__(dbapi_connection.encoders)
+        self._connection = weakref.ref(dbapi_connection)
+
+    def __missing__(self, key):
+        if not (isinstance(key, type) and issubclass(key, str)):
+            raise KeyError(key)
+        self[key] = self._encode_by_value
+        return self._encode_by_value
+
+    def _encode_by_value(self, value, _encoders):
+        connection = self._connection()
+        if connection is None:

Review Comment:
   Nit: when can this branch run? `_encode_by_value` is only called from 
mysqlclient’s `escape(o, self.encoders)` on the connection that owns this map, 
so the connection is alive at that point. Could the branch be dropped, or kept 
with a one-line comment on why the weakref is there?



-- 
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]

Reply via email to