summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
authorFrancesco Panico <panico.francesco@gmail.com>2023-07-21 09:29:27 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-07-21 09:33:16 +0200
commitafc880571d5f5a16b977070b15014f9583524898 (patch)
tree1ef1cad563b0f4dbfba3d5ccd979f46dbb77aff0 /django/db/models/sql/query.py
parentaddbc90049083f1d5f7ac138ed00111b71a75233 (diff)
Refs #34362 -- Added get_child_with_renamed_prefix() hook.
Diffstat (limited to 'django/db/models/sql/query.py')
-rw-r--r--django/db/models/sql/query.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 1608d19480..ac735012f1 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -73,14 +73,17 @@ def get_children_from_q(q):
yield child
+def get_child_with_renamed_prefix(prefix, replacement, child):
+ if isinstance(child, Node):
+ return rename_prefix_from_q(prefix, replacement, child)
+ lhs, rhs = child
+ lhs = lhs.replace(prefix, replacement, 1)
+ return lhs, rhs
+
+
def rename_prefix_from_q(prefix, replacement, q):
return Q.create(
- [
- rename_prefix_from_q(prefix, replacement, c)
- if isinstance(c, Node)
- else (c[0].replace(prefix, replacement, 1), c[1])
- for c in q.children
- ],
+ [get_child_with_renamed_prefix(prefix, replacement, c) for c in q.children],
q.connector,
q.negated,
)