Fixes #5382
Passing 0 or 0.0 to clear_callback_data currently clears all cached keyboard data, although the equivalent UTC epoch datetime applies the documented "older than" cutoff. This can discard keyboards that are newer than the supplied cutoff.
Check time_cutoff is None before clearing the entire mapping. Numeric zero then follows the existing timestamp comparison path. The public API, datetime conversion, and clear_callback_queries() behavior remain unchanged.
Add a parametrized regression test for integer zero, float zero, UTC epoch datetime, explicit None, and a future timestamp. The fixture includes entries before, exactly at, and after the epoch, and checks that callback-query IDs are preserved. Existing tests continue covering omitted cutoffs, query-ID clearing, and positive timestamp/timezone conversion.
Validation on CPython 3.12.13, with sockets disabled:
python -m pytest tests/ext/test_callbackdatacache.py --disable-socket -vv
Original tests on original source: 47 passed, 2 skipped
Regression tests on original source: 2 failed, 50 passed, 2 skipped
Regression tests on patched source: 52 passed, 2 skipped
The two expected failures on the original source are the integer-zero and float-zero regression cases. The skipped tests concern running without the optional callback-data dependency, which is installed for this run. No Telegram requests are needed.
Changed-file checks also pass using the versions pinned in .pre-commit-config.yaml: Ruff 0.16.8 lint and formatting, Mypy 1.20.2, and Pylint 4.1.3 (the latter on CPython 3.14.6, as required by its hook). These tools were invoked directly; no hooks were installed.
Checklist:
- Added regression tests and ran the affected test file.
- Restored the existing documented contract without adding or changing public APIs.
- Kept existing datetime, no-cutoff, and query-ID clearing behavior.
The repository's Chango workflow creates the changelog fragment for a PR. Suggested bug-fix note: "Fixed CallbackDataCache.clear_callback_data treating a zero UNIX timestamp cutoff as a request to clear all keyboard data."
AI disclosure: Codex assisted with part of the code and this description.