Copilot commented on code in PR #41804:
URL: https://github.com/apache/superset/pull/41804#discussion_r3538533855
##########
tests/unit_tests/models/helpers_test.py:
##########
@@ -3410,3 +3410,71 @@ def fake_engine(*args, **kwargs):
# ```forecasts.original`.`total_cost``` (the regression), so this negative
# assertion catches the actual failure mode, not just an exact-string
match.
assert "`forecasts.original`" not in sql
+
+
[email protected](
+ "native_type",
+ ["UUID", "uuid", "Nullable(UUID)"],
+)
[email protected](
+ "op",
+ ["LIKE", "ILIKE", "NOT LIKE", "NOT ILIKE"],
+)
+def test_like_filter_on_uuid_column_casts_to_string(
+ database: Database, native_type: str, op: str
+) -> None:
+ """
+ LIKE-family filters on native UUID columns must cast the column to string.
+
+ UUID columns map to ``GenericDataType.STRING``, so the generic-type guard
+ alone skips the string cast — but engines such as PostgreSQL and ClickHouse
+ reject LIKE/ILIKE against a raw UUID column (issue #41795: table chart
+ server-pagination search fails with e.g. "Illegal type UUID of argument of
+ function ilike"). The native column type must force the cast.
+ """
+ from superset.connectors.sqla.models import SqlaTable, TableColumn
+
+ table = SqlaTable(
+ database=database,
+ schema=None,
+ table_name="t",
+ columns=[TableColumn(column_name="event_id", type=native_type)],
+ )
+
+ result = table.get_sqla_query(
+ columns=["event_id"],
+ metrics=[],
+ extras={},
+ filter=[{"col": "event_id", "op": op, "val": "abc%"}],
+ granularity=None,
+ is_timeseries=False,
+ orderby=[],
+ )
+ sql = str(result.sqla_query)
+ assert "CAST" in sql.upper(), f"Expected string cast in SQL: {sql}"
Review Comment:
Asserting on the presence of the literal substring `CAST` can be brittle
across SQLAlchemy dialects/compilers (some may render casts differently). A
more robust test would assert on the SQLAlchemy expression structure (eg, that
the filter’s LHS is a `Cast`/typed expression) or compile with a specific
dialect and assert the casted column is used in the LIKE/ILIKE predicate.
##########
superset/models/helpers.py:
##########
@@ -250,6 +250,18 @@ def json_to_dict(json_str: str) -> dict[Any, Any]:
return {}
+def is_uuid_native_type(native_type: Optional[str]) -> bool:
+ """
+ Return True if a native column type represents a UUID.
+
+ Engines such as PostgreSQL and ClickHouse expose native UUID column types
+ (e.g. ``UUID``, ``Nullable(UUID)``) that map to ``GenericDataType.STRING``
+ yet reject LIKE/ILIKE against the raw column, so these columns need an
+ explicit cast to string before pattern matching.
+ """
+ return native_type is not None and "uuid" in native_type.lower()
Review Comment:
The UUID detection is very permissive: any native type containing the
substring `uuid` will be treated as UUID (including unrelated types or comments
embedded in type strings). To reduce false positives, prefer a stricter match
(e.g., token/word-boundary or wrapper-aware matching for patterns like `UUID`,
`Nullable(UUID)`, `UUID(...)`) and consider trimming whitespace first.
##########
superset/models/helpers.py:
##########
@@ -3746,7 +3758,11 @@ def get_sqla_query( # pylint:
disable=too-many-arguments,too-many-locals,too-ma
utils.FilterOperator.ILIKE,
utils.FilterOperator.LIKE,
}:
- if target_generic_type != GenericDataType.STRING:
+ # Native UUID columns report GenericDataType.STRING but
+ # reject LIKE/ILIKE without a cast (see issue #41795)
+ if target_generic_type != GenericDataType.STRING or (
+ is_uuid_native_type(col_type)
+ ):
sqla_col = sa.cast(sqla_col, sa.String)
Review Comment:
The same UUID-cast condition and comment are duplicated in both the
LIKE/ILIKE and NOT LIKE/NOT ILIKE branches. Consider computing a single
`needs_string_cast_for_like` boolean (or extracting a small helper) and reusing
it in both places to avoid future drift if this logic changes.
--
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]