Skip to content

Preserve InlineKeyboardButton Arguments During callback_data Replacement #5159

Open
harshil21 wants to merge 4 commits intomasterfrom
cbdc-bug
Open

Preserve InlineKeyboardButton Arguments During callback_data Replacement #5159
harshil21 wants to merge 4 commits intomasterfrom
cbdc-bug

Conversation

@harshil21
Copy link
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
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.

Copy link
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
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.

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

Labels

🔌 bug pr description: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants