From 14917c9ae272f47d23401100faa6cefa8e1728bf Mon Sep 17 00:00:00 2001 From: David Wobrock Date: Thu, 21 Dec 2023 23:20:36 +0100 Subject: Fixed #35050 -- Fixed prefixing field names in FilteredRelation(). Thanks Mark Zorn for the report. Regression in 59f475470494ce5b8cbff816b1e5dafcbd10a3a3. --- django/db/models/sql/query.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'django/db/models/sql/query.py') diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 7166b8cb5d..a79d66eb21 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -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( -- cgit v1.3