#36029: Deep conditions in FilteredRelation raise ProgrammingError if annotation
reused
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls):
Here's a better unit test that asserts ValueError is raised. This passes
if you adjust the lookup to add an explicit `__exact`, so hopefully the
solve is to just account for implicit exact when counting relation depths:
{{{#!diff
diff --git a/tests/filtered_relation/tests.py
b/tests/filtered_relation/tests.py
index 82caba8662..80401f4186 100644
--- a/tests/filtered_relation/tests.py
+++ b/tests/filtered_relation/tests.py
@@ -668,6 +668,20 @@ class FilteredRelationTests(TestCase):
),
)
+ def test_condition_deeper_relation_name_implicit_exact(self):
+ msg = (
+ "FilteredRelation's condition doesn't support nested
relations "
+ "deeper than the relation_name (got "
+ "'book__editor__name' for 'book')."
+ )
+ with self.assertRaisesMessage(ValueError, msg):
+ Author.objects.annotate(
+ book_editor=FilteredRelation(
+ "book",
+ condition=Q(book__editor__name="b"),
+ ),
+ )
+
def test_with_empty_relation_name_error(self):
with self.assertRaisesMessage(ValueError, "relation_name cannot
be empty."):
FilteredRelation("", condition=Q(blank=""))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36029#comment:2>
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 visit
https://groups.google.com/d/msgid/django-updates/01070193e4f31667-8b6cc67a-5f32-442d-84f0-582bb92739ff-000000%40eu-central-1.amazonses.com.