fix(server): avoid out-of-range datetime task ordering - #1220
Open
Jokasa7 wants to merge 1 commit into
Open
Conversation
🧪 Code Coverage (vs
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
DatabaseTaskStore.list()currently makes NULL timestamps sort last bycoalescing them to
datetime.min(year 0001). MySQL documents year 1000 as thelower bound of its supported
DATETIMErange. Current MySQL versions may stillaccept year 0001, so this is a portability and specification-conformance risk
rather than a consistently reproducible runtime failure.
This change replaces the datetime sentinel with an explicit ordering key:
CASEexpression ranks non-NULL timestamps before NULL timestamps;This preserves the existing list and cursor-pagination order without binding an
out-of-range datetime. It also avoids
NULLS LAST, which MySQL does not supportand which was previously removed in #651.
The regression test observes SQLAlchemy's compiled execution parameters and
fails if
list()binds a datetime before year 1000. With the test applied to thebase implementation, the SQLite case failed by capturing the year-0001
sentinel. With this change, the same test passes on SQLite, PostgreSQL 15, and
MySQL 8.0, alongside the existing ordering and pagination matrix.
Validation
./scripts/lint.sh— Ruff check/format passed;ty checkpassed./scripts/run_db_tests.sh -k test_list_tasks— 36 passed across SQLite,PostgreSQL 15, and MySQL 8.0
uv run pytest tests/integration/cross_version/client_server/test_client_server.py -q— 4 passed
uv run pytest— 1971 passed, 92 skipped, 3 xfailed, 1 xpasseduv run pytest --cov=src --cov-report=term-missing— same test result,93% total coverage
git diff --check— passedChecklist
CONTRIBUTINGguide and repository AI workflow documents.unchanged.
Fixes #1219 🦕
AI assistance was used for issue and code-path research and for drafting. I
reviewed the final diff and ran every validation command listed above.