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

Don't modify return values of manager methods in place, modify a copy instead #2345

Conversation

jkaikkosplk
Copy link
Contributor

I have made things!

#2343 and #1917 seem to be caused by _process_dynamic_method modifying the return types of QuerySet methods, while they're still being referenced by the base QuerySet class's methods. This works fine the first time a method's type is resolved, but since it modifies the base QuerySet's return value too (if it's a Union or something like list[T]), it gets rid of the TypeVar on the base QuerySet class. When we try to resolve the return type again from another manager from another model, the Generic is no longer there and we end up with whatever first replaced that Generic.

Creating a copy seems to fix it, but then again, I have no idea what I'm doing 🤷

Related issues

@jkaikkosplk jkaikkosplk force-pushed the jk/fix_union_return_types_on_manager_methods branch from 3d384bc to b75a5c7 Compare August 21, 2024 09:34
@jkaikkosplk jkaikkosplk force-pushed the jk/fix_union_return_types_on_manager_methods branch from b75a5c7 to 117713f Compare August 21, 2024 09:58
@jkaikkosplk jkaikkosplk force-pushed the jk/fix_union_return_types_on_manager_methods branch from 117713f to 127034f Compare August 21, 2024 10:11
Copy link
Member

@flaeppe flaeppe left a comment

Choose a reason for hiding this comment

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

Thank you!

@flaeppe flaeppe merged commit 84712b7 into typeddjango:master Aug 21, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants