1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #35050 -- Fixed prefixing field names in FilteredRelation().

Thanks Mark Zorn for the report.

Regression in 59f4754704.
This commit is contained in:
David Wobrock
2023-12-21 23:20:36 +01:00
committed by Mariusz Felisiak
parent 623597c786
commit 14917c9ae2
4 changed files with 45 additions and 2 deletions

View File

@@ -94,14 +94,16 @@ def get_child_with_renamed_prefix(prefix, replacement, child):
return rename_prefix_from_q(prefix, replacement, child)
if isinstance(child, tuple):
lhs, rhs = child
lhs = lhs.replace(prefix, replacement, 1)
if lhs.startswith(prefix + LOOKUP_SEP):
lhs = lhs.replace(prefix, replacement, 1)
if not isinstance(rhs, F) and hasattr(rhs, "resolve_expression"):
rhs = get_child_with_renamed_prefix(prefix, replacement, rhs)
return lhs, rhs
if isinstance(child, F):
child = child.copy()
child.name = child.name.replace(prefix, replacement, 1)
if child.name.startswith(prefix + LOOKUP_SEP):
child.name = child.name.replace(prefix, replacement, 1)
elif hasattr(child, "resolve_expression"):
child = child.copy()
child.set_source_expressions(