eschutho opened a new pull request, #45892:
URL: https://github.com/apache/superset/pull/45892

   ### SUMMARY
   Searching (`?q=`) in a filter value dropdown on a non-text column (e.g. a 
NUMERIC column on PostgreSQL) returned a 500, because the generated predicate 
was `lower(<numeric col>) LIKE ...` and `lower()` is not defined for non-string 
types on strict engines.
   
   **Root cause:** `build_like_predicate` in `superset/models/helpers.py` 
always did `sa.func.lower(expr).contains(...)`. It is called from 
`ExploreMixin.values_for_column`, so any non-string column failed on engines 
such as PostgreSQL (`function lower(numeric) does not exist`).
   
   **Fix:** if `expr.type` is not a `sa.String` subtype (numeric, integer, 
boolean, date, or untyped/`NullType`), wrap it in `sa.cast(expr, sa.String)` 
before `lower()`. Text columns are untouched, so their generated SQL is 
unchanged. BigQuery's no-`ESCAPE` behaviour is preserved.
   
   **Tradeoffs**
   - Numeric search now matches against the `CAST(... AS VARCHAR)` string 
representation. How engines render floats/booleans as strings differs, so 
matches on those types are engine-dependent.
   - No change for text columns.
   - ClickHouse rejecting `ESCAPE` on this same predicate is a known, separate 
issue and is not addressed here.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A
   
   ### TESTING INSTRUCTIONS
   - `pytest tests/unit_tests/models/helpers_test.py -k like_predicate`
   - Manually: on a Postgres dataset with a numeric column, open a filter on 
that column and type a search term in the value dropdown; it should return 
matching values instead of an error.
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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