From: Romuald Brunet Date: Mon, 17 Sep 2018 15:44:50 +0000 (-0400) Subject: Look for dict builtin in InstanceState cleanup X-Git-Tag: rel_1_3_0b1~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=505941259e4e7181a176e74b3de0b7d96c444e29;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Look for dict builtin in InstanceState cleanup Added a check within the weakref cleanup for the :class:`.InstanceState` object to check for the presence of the ``dict`` builtin, in an effort to reduce error messages generated when these cleanups occur during interpreter shutdown. Pull request courtesy Romuald Brunet. Change-Id: If27b94d50a32767de8b4147c09fa423f71596004 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/472 --- diff --git a/doc/build/changelog/unreleased_12/pr472.rst b/doc/build/changelog/unreleased_12/pr472.rst new file mode 100644 index 0000000000..baa5741260 --- /dev/null +++ b/doc/build/changelog/unreleased_12/pr472.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, orm + + Added a check within the weakref cleanup for the :class:`.InstanceState` + object to check for the presence of the ``dict`` builtin, in an effort to + reduce error messages generated when these cleanups occur during interpreter + shutdown. Pull request courtesy Romuald Brunet. diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py index 70420ca509..03d68ab820 100644 --- a/lib/sqlalchemy/orm/state.py +++ b/lib/sqlalchemy/orm/state.py @@ -369,6 +369,13 @@ class InstanceState(interfaces.InspectionAttr): Will not work otherwise! """ + + # Python builtins become undefined during interpreter shutdown. + # Guard against exceptions during this phase, as the method cannot + # proceed in any case if builtins have been undefined. + if dict is None: + return + instance_dict = self._instance_dict() if instance_dict is not None: instance_dict._fast_discard(self)