Skip to content

Conversation

UnknownPlatypus
Copy link
Contributor

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

Copy link
Member

@sobolevn sobolevn left a 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)
Copy link
Member

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?

Copy link
Contributor Author

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 :/

Copy link
Member

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.

Copy link
Member

@sobolevn sobolevn Sep 24, 2025

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

Copy link
Contributor Author

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

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5.2.3 regression with .annotate that forbids overriding existing fields
2 participants