From 252eaca87fc0459dae71c771ca94bf2772127e5a Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 16 Jul 2024 14:00:30 -0400 Subject: [PATCH] Doc'd purpose of tuple() in SQLCompiler.get_from_clause(). It was added in 01d440fa1e6b5c62acfa8b3fde43dfa1505f93c6 to prevent "RuntimeError: OrderedDict mutated during iteration". That particular issue was fixed in d660cee5bc68b597503c2a16f3d9928d52f93fb4 but the issue could remain in Join.as_sql() subclasses. Co-authored-by: Simon Charette --- django/db/models/sql/compiler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index fe22163961..98feb42716 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -1134,6 +1134,9 @@ class SQLCompiler: """ result = [] params = [] + # Copy alias_map to a tuple in case Join.as_sql() subclasses (objects + # in alias_map) alter compiler.query.alias_map. That would otherwise + # raise "RuntimeError: dictionary changed size during iteration". for alias, from_clause in tuple(self.query.alias_map.items()): if not self.query.alias_refcount[alias]: continue