Repository navigation
fix: accept handlers with **kwargs in inject - #47
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #45
injectappended its keyword-onlymodern_di_containerparameter to the end of the wrapper signature. For a handler ending in**kwargs, that put a keyword-only parameter after the variadic keyword one, andinspect.SignatureraisedValueErrorat decoration time.Changes:
VAR_KEYWORDparameter. Signatures without**kwargscome out exactly as before.FromDIparameter names from the incoming kwargs before calling the handler. aiogram passes the whole data dict to any callback whose signature has**kwargs, so aFromDIparameter named like a data key (for examplebot) would otherwise fail with "got multiple values for keyword argument". The resolved dependency takes that name, which matches what already happens without**kwargs, where aiogram filters data by the visible signature and never sends those names. The audit repro for this issue used exactly that case, so fixing only the signature would have traded the decoration error for a dispatch error.injectadded the parameter, so it does not leak into the handler's**kwargs. A handler that declaresmodern_di_containeritself still receives it.Tests (each failed before the fix):
FromDIparameter and**kwargsgets its dependency through a real dispatch, andkwargsholds aiogram'sbotbut notmodern_di_container.**kwargslast, and a handler without**kwargsends with the keyword-only container parameter as before.FromDIparameter namedbotnext to**kwargsresolves from the container, and other aiogram data still reacheskwargs.