Skip to content

Fix: Add .as_(bot) to ReplyCallbackQuery.message for fake callbacks - #531

Open
K1rL3s wants to merge 3 commits into
Tishka17:developfrom
K1rL3s:fix/missing-as-bot
Open

K1rL3s wants to merge 3 commits into
Tishka17:developfrom
K1rL3s:fix/missing-as-bot

Conversation

@K1rL3s

@K1rL3s K1rL3s commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR fixes an issue where callback.message.bot was missing for ReplyCallbackQuery objects from reply keyboards.

Previously, the simulated message object lacked the associated Bot instance due to a missing .as_(bot) call, causing errors when accessing callback.message.bot in handlers.

Now, the message is correctly linked to the Bot instance, ensuring proper context for reply keyboard callbacks

Summary by CodeRabbit

  • Tests

    • Added end-to-end test validating reply-keyboard button interaction and dialog flow.
  • Bug Fixes

    • Ensured middleware uses the provided bot instance when routing reply-based intents.
    • Improved test message manager to track and reproduce keyboard markup accurately.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d2896ac4-eb35-4c91-84a9-0d845a31e631

📥 Commits

Reviewing files that changed from the base of the PR and between 1d118bd and 675039a.

📒 Files selected for processing (1)
  • src/aiogram_dialog/test_tools/mock_message_manager.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/aiogram_dialog/test_tools/mock_message_manager.py

📝 Walkthrough

Walkthrough

Adds Bot typing in intent middleware, tracks last reply markup in MockMessageManager and updates show_message behavior, and adds an end-to-end test that exercises a reply-keyboard button click and validates bot context on the resulting callback.

Changes

Reply keyboard intent routing

Layer / File(s) Summary
Intent middleware bot typing
src/aiogram_dialog/context/intent_middleware.py
Bot type imported; a local bot: Bot = data["bot"] is used and the simulated ReplyCallbackQuery is finalized with .as_(bot).
Mock message manager reply markup tracking
src/aiogram_dialog/test_tools/mock_message_manager.py
Adds InlineKeyboardMarkup import, introduces last_reply_markup cleared by reset_history, records new_message.reply_markup in show_message, and sets outgoing Message.reply_markup to None for ReplyKeyboardMarkup or a deep-copied markup otherwise.
Reply keyboard button click test
tests/test_reply_keyboard.py
New test module: MainSG state, on_click handler that asserts callback.message.bot matches middleware bot, dialog window with a reply-keyboard button, /start handler, and an async test that sends /start, clicks the button, and asserts no extra messages were sent.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 A keyboard of replies, pressed with care,
The bot steps in neatly, typed and aware,
Markup remembered, then handled with grace,
A click completes dialog — no stray message to chase.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding .as_(bot) to ReplyCallbackQuery for reply keyboard callbacks.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/aiogram_dialog/test_tools/mock_message_manager.py`:
- Around line 63-65: In MockMessageManager, reset_history() currently doesn't
clear self.last_reply_markup which allows stale keyboard markup to persist
across tests; update reset_history() to explicitly set self.last_reply_markup =
None (alongside existing history clears) so that the mock keyboard state is
reset when reset_history() is called.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6418569e-6acd-425d-bf82-071849e168a1

📥 Commits

Reviewing files that changed from the base of the PR and between 08abdf0 and 1d118bd.

📒 Files selected for processing (3)
  • src/aiogram_dialog/context/intent_middleware.py
  • src/aiogram_dialog/test_tools/mock_message_manager.py
  • tests/test_reply_keyboard.py

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.

1 participant