-
-
Notifications
You must be signed in to change notification settings - Fork 506
Allow to annotate existing model field de-selected via prior .values
/.values_list
calls
#2836
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, except one question :)
# For non-named values_list, the row type does not encode column names. | ||
# Attach selected field names to the returned QuerySet instance so that | ||
# subsequent annotate() can make an informed decision about name conflicts. | ||
ret.extra_attrs = ExtraAttrs(attrs={}, immutable=set(field_lookups), mod_name=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: shouldn't we also set attrs
when setting immutable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understand of this ExtraAttrs
thingy, it's not supposed to be used like that and we are kinda hacking around to add metadata per Instance
. I can add the attrs dict but we will ignore it and I think mypy too :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add this, because leaving this inconsistency will blow up at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, consider using copy_with_extra_attr
? Or any other way of preserving existing .extra_attrs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, consider using copy_with_extra_attr? Or any other way of preserving existing .extra_attrs
We only set extra_attrs on this type here and the django behavior of chained values_list
is that the last one override the others. I can add a comment to say that, this is not obvious reading the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would still prefer to preserve, some other plugin / feature might modify it.
I have made things!
I've tried to avoid as much as possible false positive on loosely typed cases.
cc @asottile-sentry , would be awesome if can try to cherry-pick a1f80ea to see if it fixes your issue.
Related issues
Fixes #2818