mirror of
https://github.com/django/django.git
synced 2025-08-14 22:09:12 +00:00
Fixed #36029 -- Handled implicit exact lookups in condition depth checks for FilteredRelation.
This commit is contained in:
parent
45dc2aaa2a
commit
c3a681659c
@ -1704,12 +1704,12 @@ class Query(BaseExpression):
|
|||||||
"relations outside the %r (got %r)."
|
"relations outside the %r (got %r)."
|
||||||
% (filtered_relation.relation_name, lookup)
|
% (filtered_relation.relation_name, lookup)
|
||||||
)
|
)
|
||||||
else:
|
if len(lookup_field_parts) > len(relation_field_parts) + 1:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"FilteredRelation's condition doesn't support nested "
|
"FilteredRelation's condition doesn't support nested "
|
||||||
"relations deeper than the relation_name (got %r for "
|
"relations deeper than the relation_name (got %r for "
|
||||||
"%r)." % (lookup, filtered_relation.relation_name)
|
"%r)." % (lookup, filtered_relation.relation_name)
|
||||||
)
|
)
|
||||||
filtered_relation.condition = rename_prefix_from_q(
|
filtered_relation.condition = rename_prefix_from_q(
|
||||||
filtered_relation.relation_name,
|
filtered_relation.relation_name,
|
||||||
alias,
|
alias,
|
||||||
|
@ -668,6 +668,19 @@ 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):
|
def test_with_empty_relation_name_error(self):
|
||||||
with self.assertRaisesMessage(ValueError, "relation_name cannot be empty."):
|
with self.assertRaisesMessage(ValueError, "relation_name cannot be empty."):
|
||||||
FilteredRelation("", condition=Q(blank=""))
|
FilteredRelation("", condition=Q(blank=""))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user