Skip to content

Preserve InlineKeyboardButton Arguments During callback_data Replacement #5159

Merged
harshil21 merged 4 commits intomasterfrom
cbdc-bug
Mar 14, 2026
Merged

Preserve InlineKeyboardButton Arguments During callback_data Replacement #5159
harshil21 merged 4 commits intomasterfrom
cbdc-bug

Conversation

@harshil21
Copy link
Copy Markdown
Member

Fixes the bug as reported in https://t.me/pythontelegrambotgroup/789176

This bug only happened when the user had arbitrary_callback_data enabled.

I used a deepcopy instead of adding more arguments during initialization so we don't have to touch the file for future new arguments.

@harshil21 harshil21 added the 🔌 bug pr description: bug label Mar 8, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an issue where replacing callback_data in InlineKeyboardButtons (when arbitrary_callback_data is enabled) drops other button attributes by cloning the original button before mutation.

Changes:

  • Update CallbackDataCache.process_keyboard to deepcopy buttons before updating callback_data.
  • Extend the callback data cache test to assert preservation of non-callback_data attributes.
  • Add an unreleased changelog entry for the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
tests/ext/test_callbackdatacache.py Adds assertions to verify additional InlineKeyboardButton attributes are preserved after callback_data replacement.
src/telegram/ext/_callbackdatacache.py Clones buttons before modifying callback_data to preserve all original button attributes.
changes/unreleased/5159.oRWyrKjKtGSS28NxvnJnCy.toml Adds an unreleased note describing the behavior change/fix.

Comment thread tests/ext/test_callbackdatacache.py Outdated
Comment thread src/telegram/ext/_callbackdatacache.py Outdated
Comment thread src/telegram/ext/_callbackdatacache.py Outdated
Comment thread changes/unreleased/5159.oRWyrKjKtGSS28NxvnJnCy.toml Outdated
Copy link
Copy Markdown
Member

@aelkheir aelkheir left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread src/telegram/ext/_callbackdatacache.py Outdated
Comment thread src/telegram/ext/_callbackdatacache.py Outdated
Copy link
Copy Markdown
Member

@Poolitzer Poolitzer left a comment

Choose a reason for hiding this comment

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

LGTM

@harshil21 harshil21 merged commit 6665c14 into master Mar 14, 2026
19 of 30 checks passed
@harshil21 harshil21 deleted the cbdc-bug branch March 14, 2026 00:40
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

🔌 bug pr description: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants