Twiink opened a new pull request, #45671:
URL: https://github.com/apache/superset/pull/45671
### SUMMARY
Quarter truncation drops an explicit UTC offset because it converts the
input datetime through a pandas Period. For example,
`DATETRUNC(DATETIME('2024-05-31T12:34:56+08:00'), QUARTER)` produces a naive
datetime, while month and year truncation preserve the offset. Pairing this
quarter boundary with an offset-aware end date makes `get_since_until` raise
`TypeError: can't compare offset-naive and offset-aware datetimes`.
Use `datetime.replace` to set the quarter's first month, first day, and
midnight together, preserving the input timezone. Add coverage for all twelve
months with naive, UTC, positive-offset, and negative-offset inputs, plus range
parsing with aware endpoints. Document the offset-preserving behavior.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable; this is a backend datetime parsing fix.
For the expression above:
- Before: `2024-04-01T00:00:00`
- After: `2024-04-01T00:00:00+08:00`
### TESTING INSTRUCTIONS
1. In a configured Superset Python environment, call:
```python
from superset.utils.date_parser import get_since_until
get_since_until(
"DATETRUNC(DATETIME('2024-05-31T12:34:56+08:00'), QUARTER) : "
"DATETIME('2024-07-01T00:00:00+08:00')"
)
```
Verify that the bounds are April 1 and July 1 at midnight, both retaining
`+08:00`, without a `TypeError`.
2. Run:
```bash
TZ=UTC python -m pytest tests/unit_tests/utils/date_parser_tests.py
tests/unit_tests/utils/test_date_parsing.py -q
TZ=UTC python -m pytest
tests/unit_tests/charts/data/test_time_range_validation.py
tests/unit_tests/common/test_time_range_utils.py
tests/unit_tests/common/test_process_time_range.py
tests/unit_tests/queries/query_object_test.py -q
```
Local validation on Windows with Python 3.12.15: 135 parser tests and 59
caller tests passed. With the new tests on the original source, 39
offset-related cases failed and 75 cases passed. `TZ=UTC` is set at process
level for the existing frozen-time tests. The full test suite, browser
end-to-end tests, documentation build, and remote CI have not been run locally.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
AI assistance: Codex assisted with investigation, implementation, tests, and
this description.
Quality checks: Ruff 0.9.7, formatting, and the other applicable pre-commit
hooks passed; a direct pylint 3.3.7 check of the production file scored 10/10.
Windows mypy reports three `SIGALRM`/`alarm` errors in unchanged
`superset/utils/core.py`, reproduced on the original upstream source. The same
mypy environment with `--platform linux` passes for both changed Python files.
--
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]