[Django] #29789: Support nested relations in FilteredRelation's condition

196 views
Skip to first unread message

Django

unread,
Sep 24, 2018, 11:32:13 AM9/24/18
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas | Owner: nobody
Riccardi |
Type: New | Status: new
feature |
Component: Database | Version: 2.0
layer (models, ORM) | Keywords: FilteredRelation
Severity: Normal | nested relations
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
As the documentation explains, FilteredRelation's condition do not support
nested relations:

{{{

>>> Restaurant.objects.annotate(
... pizzas_with_toppings_startswith_n=FilteredRelation(
... 'pizzas__toppings',
... condition=Q(pizzas__toppings__name__startswith='n'),
... ),
... )
Traceback (most recent call last):
...
ValueError: FilteredRelation's condition doesn't support nested
relations (got 'pizzas__toppings__name__startswith').
}}}


It would be great to support nested relations in FilteredRelation's
condition (I encountered this limitation multiple times recently).

--
Ticket URL: <https://code.djangoproject.com/ticket/29789>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 25, 2018, 11:47:45 AM9/25/18
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage:
nested relations | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* cc: Nicolas Delaby (added)


Comment:

Nicolas, do you remember the reason for the restriction?

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:1>

Django

unread,
Sep 25, 2018, 1:16:55 PM9/25/18
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage:
nested relations | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Nicolas Delaby):

I simply couldn't find a way to make it work, I don't remember exactly why
and I didn't have real incitement to do it at that time.
The explicit ValueError is more a gate keeper preventing users to follow a
path we know will fail cryptically.
My suggestion would be start writing some tests, removing the ValueError
and see how it goes.
My priority at that time was to land the feature even with partial
support. Now that a big chunk is there, we can more easily improve the
support so nested relations is supported.
Unfortunately I'm at the moment away from django stack, so I Invite you,
Thomas , to give it a try, if it is important for you. You might go
further than I could.

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:2>

Django

unread,
Sep 25, 2018, 1:22:32 PM9/25/18
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master

(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* version: 2.0 => master
* stage: Unreviewed => Accepted


Comment:

If I remember correctly there was some weirdness when dealing with
exclusion of such nested filtered relations.

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:3>

Django

unread,
Jan 22, 2019, 5:39:47 PM1/22/19
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Noumbissi Valere Gille Geovan):

* owner: nobody => Noumbissi Valere Gille Geovan
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:4>

Django

unread,
Mar 2, 2019, 12:39:44 AM3/2/19
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by saber solooki):

Are you support this feature in next version or not? thank's in advance

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:5>

Django

unread,
May 6, 2019, 12:07:35 PM5/6/19
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

#30349 addressed an issue when using `exclude` with `FilteredRelation`
that might explain the `ValueError` raised when trying to add support for
nested relations.

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:6>

Django

unread,
Aug 1, 2019, 4:02:06 PM8/1/19
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Reupen Shah):

* cc: Reupen Shah (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:7>

Django

unread,
Nov 16, 2019, 1:24:22 PM11/16/19
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Alex Scott):

* cc: Alex Scott (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:8>

Django

unread,
Nov 17, 2019, 1:55:33 PM11/17/19
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Alex Scott):

Noumbissi, just wondering if you're working on this? And if so, how it's
progressing?

This problem (of needing to join to a subquery or add additional
conditions to a join that is nested more than once) seems to come up quite
a bit. I've posted my own question on StackOverflow:
https://stackoverflow.com/questions/58895627/django-queryset-with-
aggregation-and-filtered-left-join-multiple-levels-deep

In the absence of this feature, it'd be nice to have someone intimately
familiar with the ORM propose how they would tackle this as I haven't seen
a "this feature is not yet available, but as a workaround, try this
instead..". Would be very helpful.

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:9>

Django

unread,
Jan 7, 2020, 6:29:20 PM1/7/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by ferrants):

Noumbissi, Alex Scott, Nicolas Delaby
I've opened a PR for supporting Nested FilteredRelations in 2.2
I can also support this for 3.0, but I made the PR for 2.2 because I'm
using 2.2. Happy to open the PR for 3.0 as well.

Feedback is appreciated, I included comments in other places I had
examined for making the change.

https://github.com/django/django/pull/12288

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:10>

Django

unread,
Jan 8, 2020, 1:42:18 AM1/8/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

Matt, we don't accept new features to the Django 2.2 and 3.0. Please
create a PR against master branch.

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:11>

Django

unread,
Jan 8, 2020, 7:41:25 PM1/8/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Ferrante):

Thanks for the heads-up felixxm. Opened one against master:
https://github.com/django/django/pull/12293

I'll work through the test failures.

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:12>

Django

unread,
Jan 16, 2020, 6:50:31 PM1/16/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Ferrante):

Got the tests passing in https://github.com/django/django/pull/12293

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:13>

Django

unread,
Jan 17, 2020, 6:17:41 AM1/17/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/12333 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:14>

Django

unread,
Jan 22, 2020, 5:57:56 AM1/22/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:15>

Django

unread,
Feb 24, 2020, 12:33:34 PM2/24/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Ferrante):

felixxm, I've updated the PR, can you take another look? Thanks!
https://github.com/django/django/pull/12333

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:16>

Django

unread,
Feb 24, 2020, 2:07:51 PM2/24/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

Matt, Thanks, you don't need to ping me, if PR is ready for another review
just uncheck ''"Patch needs improvement"''.

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:17>

Django

unread,
Feb 25, 2020, 9:01:41 PM2/25/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Matt Ferrante):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:18>

Django

unread,
Mar 2, 2020, 9:46:00 PM3/2/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Noumbissi
| Valere Gille Geovan
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Ferrante):

Patch available here, rebased and it's good to go!
https://github.com/django/django/pull/12333

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:19>

Django

unread,
Mar 9, 2020, 6:38:20 PM3/9/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: (none)

Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Matt Ferrante):

* owner: Noumbissi Valere Gille Geovan => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:20>

Django

unread,
Mar 12, 2020, 11:53:10 AM3/12/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Matt
| Ferrante

Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Matt Ferrante):

* owner: (none) => Matt Ferrante


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:21>

Django

unread,
Apr 1, 2020, 6:41:09 PM4/1/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Matt
| Ferrante
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Ferrante):

felixxm, should I be doing something else to get this another review?

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:22>

Django

unread,
Apr 2, 2020, 12:24:55 AM4/2/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Matt
| Ferrante
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

Matt, you can ask any friend to review it. I'm sorry but you must be
patient we have many PRs in a review queue.

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:23>

Django

unread,
Jun 3, 2020, 1:50:16 PM6/3/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Matt
| Ferrante
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Ferrante):

I've been using a branch with this patch for nested FilteredRelations in
production for 4 months without issues. It works really well and added a
lot of flexibility and allowed for performance optimizations which helped
with our analytical query speed. Hoping this gets approved and changes to
"Ready for checkin" soon!

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:24>

Django

unread,
Jul 7, 2020, 8:45:08 PM7/7/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Matt
| Ferrante
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Accepted
nested relations |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

I think the proposed patch is ready to be merged. Looks like current
implementation of `FilteredRelation(condition=~Q)` might do weird things
under some circumstances but that seems like an artifact of how exclusions
against multi-valued relationship is currently implemented.

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:25>

Django

unread,
Jul 9, 2020, 5:28:16 AM7/9/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Matt
| Ferrante
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Ready for
nested relations | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:26>

Django

unread,
Jul 9, 2020, 5:35:36 AM7/9/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Matt
| Ferrante
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Ready for
nested relations | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

[https://github.com/django/django/pull/13170 PR with final edits]

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:27>

Django

unread,
Jul 9, 2020, 2:46:38 PM7/9/20
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Matt
| Ferrante
Type: New feature | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: FilteredRelation | Triage Stage: Ready for
nested relations | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"7d6916e82700896ef23c50720d8cf0de4d6b9074" 7d6916e]:
{{{
#!CommitTicketReference repository=""
revision="7d6916e82700896ef23c50720d8cf0de4d6b9074"
Fixed #29789 -- Added support for nested relations to FilteredRelation.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:28>

Django

unread,
Jul 21, 2023, 6:44:04 AM7/21/23
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Matt
| Ferrante
Type: New feature | Status: closed
Component: Database layer | Version: dev

(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: FilteredRelation | Triage Stage: Ready for
nested relations | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"e4a5527d1dc2f8183883931560f3a6dcdef0ab0c" e4a5527d]:
{{{
#!CommitTicketReference repository=""
revision="e4a5527d1dc2f8183883931560f3a6dcdef0ab0c"
Refs #29789 -- Added more tests for FilteredRelation with condition
outside of relation name.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:29>

Django

unread,
May 30, 2025, 1:05:39 AMMay 30
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Matt
| Ferrante
Type: New feature | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: FilteredRelation | Triage Stage: Ready for
nested relations | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by nad2000):

* resolution: fixed =>
* status: closed => new

Comment:

This bug resurufeced wiht 5.2. (after upgrading from 5.1.9). The queryset
causing this issue ("ValueError: FilteredRelation's condition doesn't
support nested relations deeper than the relation_name (got
'conflict_of_interests__panellist__user' for 'conflict_of_interests')."):


{{{
queryset = queryset.filter(round__panellists__user=user,
state="submitted").annotate(
coi=FilteredRelation(
"conflict_of_interests",
condition=Q(conflict_of_interests__panellist__user=user),
)
)

}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:30>

Django

unread,
May 30, 2025, 7:42:56 AMMay 30
to django-...@googlegroups.com
#29789: Support nested relations in FilteredRelation's condition
-------------------------------------+-------------------------------------
Reporter: Thomas Riccardi | Owner: Matt
| Ferrante
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: FilteredRelation | Triage Stage: Ready for
nested relations | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* resolution: => fixed
* status: new => closed

Comment:

5.2 fixed a case where the check raising `ValueError` was being evaded for
implicit `__exact` lookups. If your queryset raises an error on 5.1.9 when
adding `__exact` after `user`, then this is not a bug. See #36029.

When reporting a bug, please open a new issue: you can always reference
other tickets while doing so. Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/29789#comment:31>
Reply all
Reply to author
Forward
0 new messages