Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #470: Prevent error AsyncToSync.main_wrap() got multiple values for argument '<kwarg>' #471

Merged
merged 5 commits into from
Sep 30, 2024

Conversation

Krismix1
Copy link
Contributor

Fixes #470.

Destructuring *args and **kwargs passed in by the callee has the chance that the same kwargs names may be used as by main_wrap. If that happens, the interpreter will raise a error like: TypeError: AsyncToSync.main_wrap() got multiple values for argument 'context'.
ParamSpec requires the *args and **kwargs syntax to be used, but it is wrong execution wise.
So we work around the issue by pre-creating the awaitable outside main_wrap, which removes the need to pass *args and **kwargs.
Another alternative instead of creating the awaitable could be to use functools.partial, though that does add some performance overhead: #470 (comment).

@andrewgodwin
Copy link
Member

That's a very neat way of solving it - nice! And thanks!

@andrewgodwin andrewgodwin merged commit a916061 into django:main Sep 30, 2024
6 checks passed
@Krismix1 Krismix1 deleted the bugfix/470-duplicated-kwargs branch October 1, 2024 06:32
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.

AsyncToSync incorrectly passes arguments when called function arguments to internal wrapper
2 participants