From f3c4735c0bef6325e977876e12fc476da363ec3c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 15 Jul 2021 10:36:53 -0400 Subject: [PATCH] apply list() around weakkeydictionary iteration Fixed an issue where clearing of mappers during things like test suite teardowns could cause a "dictionary changed size" warning during garbage collection, due to iteration of a weak-referencing dictionary. A ``list()`` has been applied to prevent concurrent GC from affecting this operation. Fixes: #6771 Change-Id: I3e1d67e978b2726a282d8b327457f2d4b239a0c6 --- doc/build/changelog/unreleased_14/6771.rst | 8 ++++++++ lib/sqlalchemy/orm/decl_api.py | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 doc/build/changelog/unreleased_14/6771.rst diff --git a/doc/build/changelog/unreleased_14/6771.rst b/doc/build/changelog/unreleased_14/6771.rst new file mode 100644 index 0000000000..811ee7d825 --- /dev/null +++ b/doc/build/changelog/unreleased_14/6771.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: orm, bug + :tickets: 6771 + + Fixed an issue where clearing of mappers during things like test suite + teardowns could cause a "dictionary changed size" warning during garbage + collection, due to iteration of a weak-referencing dictionary. A ``list()`` + has been applied to prevent concurrent GC from affecting this operation. diff --git a/lib/sqlalchemy/orm/decl_api.py b/lib/sqlalchemy/orm/decl_api.py index 54e927ee47..23b89a5434 100644 --- a/lib/sqlalchemy/orm/decl_api.py +++ b/lib/sqlalchemy/orm/decl_api.py @@ -624,14 +624,14 @@ class registry(object): return itertools.chain( ( manager.mapper - for manager in self._managers + for manager in list(self._managers) if manager.is_mapped and not manager.mapper.configured and manager.mapper._ready_for_configure ), ( npm - for npm in self._non_primary_mappers + for npm in list(self._non_primary_mappers) if not npm.configured and npm._ready_for_configure ), ) -- 2.47.2