Skip to content

Commit b145b5f

Browse files
committed
Don't mutate join_ctx when normalizing join.
1 parent 039897c commit b145b5f

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

peewee.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8530,8 +8530,9 @@ def _normalize_join(self, src, dest, on, attr):
85308530
src_model, src_is_model = self._get_model(src)
85318531
dest_model, dest_is_model = self._get_model(dest)
85328532

8533+
join_ctx = self._join_ctx
85338534
if src_model and dest_model:
8534-
self._join_ctx = dest
8535+
join_ctx = dest
85358536
constructor = dest_model
85368537

85378538
# In the case where the "on" clause is a Column or Field, we will
@@ -8585,11 +8586,11 @@ def _normalize_join(self, src, dest, on, attr):
85858586
elif dest_model:
85868587
# Joining from a model-less source (subquery, CTE, table) to a
85878588
# model, e.g. join_from(cte, SomeModel, on=...).
8588-
self._join_ctx = dest
8589+
join_ctx = dest
85898590
constructor = dest_model
85908591
attr = attr or dest_model._meta.name
85918592

8592-
return (on, attr, constructor)
8593+
return (on, attr, constructor, join_ctx)
85938594

85948595
def _generate_on_clause(self, src, dest, to_field=None, on=None):
85958596
meta = src._meta
@@ -8667,7 +8668,9 @@ def join(self, dest, join_type=JOIN.INNER, on=None, src=None, attr=None):
86678668
# A lateral source correlates inside the subquery, default ON true.
86688669
if on is None and getattr(dest, '_lateral', False):
86698670
on = True
8670-
on, attr, constructor = self._normalize_join(src, dest, on, attr)
8671+
on, attr, constructor, join_ctx = self._normalize_join(
8672+
src, dest, on, attr)
8673+
self._join_ctx = join_ctx
86718674
if attr:
86728675
self._joins.setdefault(src, [])
86738676
self._joins[src].append((dest, attr, constructor, join_type))

0 commit comments

Comments
 (0)