Skip to content

fix: ensure middleware data is passed to scene entry handler#1674

Merged
JrooTJunior merged 3 commits intodev-3.xfrom
bugfix/1672
Apr 16, 2025
Merged

fix: ensure middleware data is passed to scene entry handler#1674
JrooTJunior merged 3 commits intodev-3.xfrom
bugfix/1672

Conversation

@JrooTJunior
Copy link
Member

@JrooTJunior JrooTJunior commented Apr 15, 2025

Description

Fixed an issue where the scene entry handler (enter) was not receiving data passed to the context by middleware, which could result in a TypeError.

Fixes #1672
Is an alternative solution to #1673

Plan

  • Investigate issue
  • Find acceptable solution
  • Cover changes with tests
  • Add additional test-case to the tests/issues/ directory to check that the original issue was fixed
  • Re-check solution and additional use cases
  • Update the documentation to reduce future misunderstandings about how scene endpoints work

@github-actions github-actions bot added the 3.x Issue or PR for stable 3.x version label Apr 15, 2025
@github-actions
Copy link

✔️ Changelog found.

Thank you for adding a description of the changes

@codecov
Copy link

codecov bot commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (50f84ad) to head (449ae47).
Report is 3 commits behind head on dev-3.x.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           dev-3.x     #1674   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          568       568           
  Lines        13337     13337           
=========================================
  Hits         13337     13337           
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
aiogram/fsm/scene.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JrooTJunior JrooTJunior marked this pull request as ready for review April 16, 2025 21:31
@JrooTJunior JrooTJunior requested a review from Copilot April 16, 2025 21:32
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

This PR fixes an issue where the scene entry handler was not receiving context data injected by middleware.

  • Updated the as_handler method in the scene module to merge handler and middleware keyword arguments.
  • Added tests in both issues and FSM test suites to validate that middleware data is correctly passed to scene handlers.

Reviewed Changes

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

File Description
tests/test_issues/test_1672_middleware_data_in_scene.py Added a test case confirming middleware context data propagation to scene entry.
tests/test_fsm/test_scene.py Added a test to validate merging of handler kwargs and middleware data.
aiogram/fsm/scene.py Modified as_handler to merge handler and middleware kwargs when calling scenes.enter.
Files not reviewed (2)
  • CHANGES/1672.bugfix.rst: Language not supported
  • docs/dispatcher/finite_state_machine/scene.rst: Language not supported

@JrooTJunior JrooTJunior merged commit eb84458 into dev-3.x Apr 16, 2025
23 checks passed
@JrooTJunior JrooTJunior deleted the bugfix/1672 branch April 16, 2025 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Issue or PR for stable 3.x version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scene action handlers do not pass through observer middleware, causing missing context and argument errors

2 participants