Visitar URL original
Preserve zero UNIX cutoffs in `CallbackDataCache.clear_callback_data` by CLCK0622 · Pull Request #5383 · python-telegram-bot/python-telegram-bot · GitHub
Skip to content

Preserve zero UNIX cutoffs in CallbackDataCache.clear_callback_data - #5383

Open
CLCK0622 wants to merge 1 commit into
python-telegram-bot:masterfrom
CLCK0622:callback-data-zero-cutoff
Open

CLCK0622 wants to merge 1 commit into
python-telegram-bot:masterfrom
CLCK0622:callback-data-zero-cutoff

Conversation

@CLCK0622

@CLCK0622 CLCK0622 commented Oct 20, 2026 •

Copy link
Copy Markdown

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.

Copilot AI balanced review requested due to automatic review settings October 20, 2026 16:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clear_callback_data treats a zero UNIX cutoff as a request to clear all data

2 participants