Repository navigation
Support relations in .only() - #1923
Merged
Merged
Conversation
CodSpeed Performance ReportMerging #1923 will not alter performanceComparing Summary
|
Pull Request Test Coverage Report for Build 14092795418Details
💛 - Coveralls |
henadzit
marked this pull request as ready for review
March 26, 2025 10:02
henadzit
commented
Mar 26, 2025
| self.model, | ||
| (None,), | ||
| ) | ||
| if append_item not in self._select_related_idx: |
Contributor
Author
There was a problem hiding this comment.
This check is not needed since self._select_related_idx is always empty at this point.
waketzheng
reviewed
Mar 26, 2025
| fields.append(field) | ||
| model = field.related_model | ||
| try: | ||
| fields.append(model._meta.fields_map[field_names[-1]]) |
Contributor
There was a problem hiding this comment.
Cloud you leave some comment for why put the last element out of the for loop?
waketzheng
reviewed
Mar 26, 2025
| if not any((v for _, v in related_items)): | ||
| obj = None | ||
| else: | ||
| if any((v for _, v in related_items)): |
Contributor
There was a problem hiding this comment.
I think
if any(v for _, v in related_items):is more readable
Contributor
Author
There was a problem hiding this comment.
if any(v for _, v in related_items): should be faster too because a new tuple isn't created. Updated!
Contributor
There was a problem hiding this comment.
Actually, (v for _, v in related_items) is a generator.
waketzheng
self-requested a review
March 27, 2025 08:41
waketzheng
approved these changes
Mar 27, 2025
Merged
5 of 7 tasks
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.
Description
.onlysupports selecting related fields, e.g..only("related__field").values(),.values_list()and.only()cannot be used togetherexpand_lookup_expressionthat can be used to convert the lookup expression (a__b__c) to a list of fields. Currently it is used in_join_select_relatedand_resolve_onlybut it can be reused in other places that support lookup expressions, for instance, in filters and ordering.Motivation and Context
How Has This Been Tested?
make ci+ a lot of new testsChecklist: