[Django] #34957: Cannot filter over annotated "FilteredRelation" since Django 5

4 views
Skip to first unread message

Django

unread,
Nov 8, 2023, 5:08:53 AM11/8/23
to django-...@googlegroups.com
#34957: Cannot filter over annotated "FilteredRelation" since Django 5
-----------------------------------------+------------------------
Reporter: younes-chaoui | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 5.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
After updating to django 5.0b1 I get test fails when using a filter over
annotated "FilteredRelation". This is an example :

{{{
from django.db.models import F, FilteredRelation, Q
visites = (
Visite.objects.all()
.annotate(
etat_at_date_de_visite=FilteredRelation(
"site__siteusage__etats",
condition=Q(site__siteusage__etats__date_valeur=F("date_de_visite")),
)
)
.filter(etat_at_date_de_visite__isnull=False)
)
print(visites)
}}}

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

Django

unread,
Nov 8, 2023, 5:11:13 AM11/8/23
to django-...@googlegroups.com
#34957: Cannot filter over annotated "FilteredRelation" since Django 5
-------------------------------+--------------------------------------

Reporter: younes-chaoui | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 5.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by younes-chaoui:

Old description:

> After updating to django 5.0b1 I get test fails when using a filter over
> annotated "FilteredRelation". This is an example :
>
> {{{
> from django.db.models import F, FilteredRelation, Q
> visites = (
> Visite.objects.all()
> .annotate(
> etat_at_date_de_visite=FilteredRelation(
> "site__siteusage__etats",
> condition=Q(site__siteusage__etats__date_valeur=F("date_de_visite")),
> )
> )
> .filter(etat_at_date_de_visite__isnull=False)
> )
> print(visites)
> }}}

New description:

After updating to django 5.0b1 I get test fails when using a filter over
annotated "FilteredRelation". This is an example :

{{{
from django.db.models import F, FilteredRelation, Q
visites = (
Visite.objects.all()
.annotate(
etat_at_date_de_visite=FilteredRelation(
"site__siteusage__etats",
condition=Q(site__siteusage__etats__date_valeur=F("date_de_visite")),
)
)
.filter(etat_at_date_de_visite__isnull=False)
)
print(visites)
}}}

**Tracelog**

{{{
File "/home/younes/.local/share/virtualenvs/new-p1-back-
ouzi8-CM/lib/python3.11/site-packages/django/db/models/sql/query.py", line
1913, in setup_joins
alias = self.join(connection, reuse=reuse)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/younes/.local/share/virtualenvs/new-p1-back-
ouzi8-CM/lib/python3.11/site-packages/django/db/models/sql/query.py", line
1133, in join
join.filtered_relation = filtered_relation.resolve_expression(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/younes/.local/share/virtualenvs/new-p1-back-
ouzi8-CM/lib/python3.11/site-packages/django/db/models/query_utils.py",
line 463, in resolve_expression
clone.resolved_condition = query.build_filter(
^^^^^^^^^^^^^^^^^^^
File "/home/younes/.local/share/virtualenvs/new-p1-back-
ouzi8-CM/lib/python3.11/site-packages/django/db/models/sql/query.py", line
1458, in build_filter
return self._add_q(
^^^^^^^^^^^^
File "/home/younes/.local/share/virtualenvs/new-p1-back-
ouzi8-CM/lib/python3.11/site-packages/django/db/models/sql/query.py", line
1631, in _add_q
child_clause, needed_inner = self.build_filter(
^^^^^^^^^^^^^^^^^^
File "/home/younes/.local/share/virtualenvs/new-p1-back-
ouzi8-CM/lib/python3.11/site-packages/django/db/models/sql/query.py", line
1481, in build_filter
lookups, parts, reffed_expression = self.solve_lookup_type(arg,
summarize)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/younes/.local/share/virtualenvs/new-p1-back-
ouzi8-CM/lib/python3.11/site-packages/django/db/models/sql/query.py", line
1293, in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted,
self.get_meta())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/younes/.local/share/virtualenvs/new-p1-back-
ouzi8-CM/lib/python3.11/site-packages/django/db/models/sql/query.py", line
1774, in names_to_path
pathinfos = field.get_path_info(filtered_relation)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/younes/.local/share/virtualenvs/new-p1-back-
ouzi8-CM/lib/python3.11/site-
packages/django/db/models/fields/reverse_related.py", line 241, in
get_path_info
return self.field.get_reverse_path_info(filtered_relation)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/younes/.local/share/virtualenvs/new-p1-back-
ouzi8-CM/lib/python3.11/site-packages/django/db/models/fields/related.py",
line 862, in get_reverse_path_info
PathInfo(
File "<string>", line 1, in <lambda>
RecursionError: maximum recursion depth exceeded while calling a Python
object
}}}

--

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

Django

unread,
Nov 8, 2023, 5:12:59 AM11/8/23
to django-...@googlegroups.com

Old description:

New description:

After updating to django 5.0b1 I get test fails when filtering over
annotated "FilteredRelation".

This is an example to reproduce it :

**Tracelog**

--

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

Django

unread,
Nov 8, 2023, 5:13:27 AM11/8/23
to django-...@googlegroups.com
#34957: Cannot filter over annotated "FilteredRelation" since Django 5
-------------------------------+--------------------------------------
Reporter: younes-chaoui | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 5.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Mariusz Felisiak):

Please attach your models definition.

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

Django

unread,
Nov 8, 2023, 5:14:19 AM11/8/23
to django-...@googlegroups.com
#34957: Cannot filter over annotated "FilteredRelation" since Django 5
-------------------------------+--------------------------------------
Reporter: younes-chaoui | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 5.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by younes-chaoui:

Old description:

> After updating to django 5.0b1 I get test fails when filtering over

New description:

After updating to django 5.0b1 I get exceptions when filtering over
annotated "FilteredRelation".

**Tracelog**

--

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

Django

unread,
Nov 8, 2023, 5:17:35 AM11/8/23
to django-...@googlegroups.com
#34957: Cannot filter over annotated "FilteredRelation" since Django 5
-------------------------------+--------------------------------------
Reporter: younes-chaoui | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 5.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by younes-chaoui:

Old description:

> After updating to django 5.0b1 I get exceptions when filtering over

New description:

After updating to django 5.0b1 I get **RecursionError** when filtering
over annotated "FilteredRelation".

**Tracelog**

--

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

Django

unread,
Nov 8, 2023, 5:33:04 AM11/8/23
to django-...@googlegroups.com
#34957: Cannot filter over annotated "FilteredRelation" since Django 5
-------------------------------+--------------------------------------
Reporter: younes-chaoui | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 5.0
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

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


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

Reply all
Reply to author
Forward
0 new messages