FrancescoCastaldi commented on issue #45269:
URL: https://github.com/apache/superset/issues/45269#issuecomment-6524027860
### Root Cause Analysis & Solution
In `superset/jinja_context.py:ExtraCache.get_time_filter`, the generator
expression searched for the temporal filter using direct dictionary key lookups:
```python
if flt["operator"] == FilterOperator.TEMPORAL_RANGE and flt["subject"] ==
column
```
When a query includes custom SQL adhoc filters in addition to standard
column filters, custom SQL filter definitions contain `clause`,
`expressionType`, and `sqlExpression`, but do not have `operator` or `subject`
keys. If a custom SQL filter preceded a temporal range filter in
`adhoc_filters`, accessing `flt["operator"]` raised a `KeyError`.
#### Solution
Use `.get()` when inspecting adhoc filter dictionaries:
```python
if flt.get("operator") == FilterOperator.TEMPORAL_RANGE and
flt.get("subject") == column
```
Verified with unit tests in `tests/unit_tests/jinja_context_test.py` and
committed to branch `fix/community-unanswered-issues` (commit `dacd3df417a`) at
https://github.com/FrancescoCastaldi/superset/tree/fix/community-unanswered-issues.
--
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]