Skip to content
/ django Public

Fixed #30349 -- Fixed QuerySet.exclude() on FilteredRelation.#11265

Merged
felixxm merged 1 commit intodjango:masterfrom
xmeowmeowx:ticket/30349
May 7, 2019
Merged

Fixed #30349 -- Fixed QuerySet.exclude() on FilteredRelation.#11265
felixxm merged 1 commit intodjango:masterfrom
xmeowmeowx:ticket/30349

Conversation

@xmeowmeowx
Copy link
Contributor

@xmeowmeowx xmeowmeowx commented Apr 21, 2019

https://code.djangoproject.com/ticket/30349

Using annotated FilteredRelations will raise a FieldError when coupled with exclude. This is due to not passing filtered relation fields to the subquery created in split_exclude.

I have rectified the issue by passing the filtered relation data to the newly created subquery.

Copy link
Member

@charettes charettes left a comment

Choose a reason for hiding this comment

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

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.
@felixxm felixxm changed the title Fixed #30349 -- Fixed FilteredRelation not working with exclude Fixed #30349 -- Fixed #30349 -- Fixed QuerySet.exclude() on FilteredRelation. May 7, 2019
@felixxm felixxm self-assigned this May 7, 2019
@felixxm felixxm changed the title Fixed #30349 -- Fixed #30349 -- Fixed QuerySet.exclude() on FilteredRelation. Fixed #30349 -- Fixed QuerySet.exclude() on FilteredRelation. May 7, 2019
@felixxm felixxm merged commit 6b736dd into django:master May 7, 2019
@felixxm
Copy link
Member

felixxm commented May 7, 2019

@xmeowmeowx Thanks, great job 🚀

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants