#34015: Registering lookups on relation fields should be supported.
-------------------------------------+-------------------------------------
Reporter: Thomas | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM lookup | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):
* 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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018354e62545-59211103-28fe-404b-b9d7-beffdba71d94-000000%40eu-central-1.amazonses.com.