* cc: Simon Charette, AllenJonathan (added)
* status: closed => new
* resolution: duplicate =>
* stage: Unreviewed => Accepted
Comment:
I noticed that registering transforms on related fields doesn't work at
all as we have
[https://github.com/django/django/blob/cfe3008123ed7c9e3f3a4d51d4a22f9d96634e33/django/db/models/sql/query.py#L1281-L1284
a guard] that seems completely unnecessary. A regression test:
{{{#!diff
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index 1bd72dd8b8..facf0fc421 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -1621,6 +1621,19 @@ class Queries4Tests(TestCase):
date_obj,
)
+ def test_related_transform(self):
+ from django.db.models.functions import ExtractYear
+ from django.test.utils import register_lookup
+
+ date_obj = DateTimePK.objects.create()
+ extra_obj = ExtraInfo.objects.create(info="extra", date=date_obj)
+ fk_field = ExtraInfo._meta.get_field("date")
+ with register_lookup(fk_field, ExtractYear):
+ self.assertSequenceEqual(
+ ExtraInfo.objects.filter(date__year=2022),
+ [extra_obj],
+ )
+
def test_ticket10181(self):
# Avoid raising an EmptyResultSet if an inner query is probably
# empty (and hence, not executed).
}}}
We could consider this a release blocker after
10178197d57476f69688d4535e550a1ea3a5eac5 🤔.
--
Ticket URL: <https://code.djangoproject.com/ticket/34015#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.