[#1672] Fix scene handlers not receiving context from observer middlewares#1673
[#1672] Fix scene handlers not receiving context from observer middlewares#1673Vadim-Khristenko wants to merge 7 commits intoaiogram:dev-3.xfrom
Conversation
✔️ Changelog found.Thank you for adding a description of the changes |
There was a problem hiding this comment.
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
Files not reviewed (1)
- CHANGES/1673.bugfix.rst: Language not supported
Comments suppressed due to low confidence (2)
aiogram/fsm/scene.py:589
- [nitpick] The function name '_actual_handler' is generic; consider renaming it to better reflect its role in invoking the action configuration with middleware context (for example, '_invoke_action_with_middleware').
async def _actual_handler(event, **data):
aiogram/fsm/scene.py:592
- Automated tests are missing for the new observer middleware branch. Consider adding tests to ensure this behavior remains reliable.
await observer.wrap_outer_middleware(
…(missed in previous commit)
|
Fix middleware chain in scene handling Found and fixed an issue where standard middlewares caused a |
|
@JrooTJunior I’ve pushed an updated version that fully fixes middleware handling in scenes (both outer and standard middlewares). |
|
Thanks for you contribution. I checked the issue and purposed solution and my conclusion is that the proposed solution is overcomplicated and is not correct. Explanation:The handler that is the entry point into the scene at the time of the call has already passed the middleware chain, so in no case should it be reprocessed again, also by design the handler should not know how exactly it was called, it should expect that it will be called correctly and this principle is violated in the proposed solution. Also, The correct solution is very simple and consists in replacing only two lines of code that should accept and pass arguments to the callback in the handler. ConclusionI will make this correction in the near future and I reject this proposed solution. |
Description
This PR fixes the issue where scene action handlers do not receive context and data injected by observer (
outer_middleware) middlewares, leading to missing argument errors. Now, scene handlers (such asenter,leave, etc.) properly receive context/data from observer middlewares, matching the behavior of regular handlers.Fixes #1672
Type of change
How Has This Been Tested?
No new automated tests have been added yet, but I can provide them if required.
The fix was manually tested using the MRE from #1672, which now works as expected after this change.
Test Configuration:
Checklist:
Note:
No new tests are included in this PR, but I am ready to add them if necessary. The fix was verified with the MRE provided in #1672.