Fixed #30349 -- Fixed QuerySet.exclude() on FilteredRelation.#11265
Merged
felixxm merged 1 commit intodjango:masterfrom May 7, 2019
Merged
Fixed #30349 -- Fixed QuerySet.exclude() on FilteredRelation.#11265felixxm merged 1 commit intodjango:masterfrom
felixxm merged 1 commit intodjango:masterfrom
Conversation
charettes
approved these changes
Apr 21, 2019
Member
charettes
left a comment
There was a problem hiding this comment.
This has little to do with this patch but it's a bit weird that an annotate filtered_relation needs special care in this method while normal annotations reference don't.
It makes me wonder why FilteredRelation relation was implemented as a special expression at the Query level given the ORM already has support for expressing filtered JOINs through get_path_info. I assume changing FilteredRelation` to use this API would lift a few of it's current limitations such as spawning relation fields.
Anyway, this patch seems the best solution until a proper refactor of how these objects are handled.
Using annotated FilteredRelations raised a FieldError when coupled with exclude(). This is due to not passing filtered relation fields to the subquery created in split_exclude(). We fixed this issue by passing the filtered relation data to the newly created subquery. Secondly, in the case where an INNER JOIN is used in the excluded subquery, the ORM would trim the filtered relation INNER JOIN in attempt to simplify the query. This will also remove the ON clause filters generated by the FilteredRelation. We added logic to not trim the INNER JOIN if it is from FilteredRelation.
Member
|
@xmeowmeowx Thanks, great job 🚀 |
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.
https://code.djangoproject.com/ticket/30349
Using annotated
FilteredRelationswill raise aFieldErrorwhen coupled withexclude. This is due to not passing filtered relation fields to the subquery created insplit_exclude.I have rectified the issue by passing the filtered relation data to the newly created subquery.