]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Look for dict builtin in InstanceState cleanup
authorRomuald Brunet <romuald@gandi.net>
Mon, 17 Sep 2018 15:44:50 +0000 (11:44 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 18 Sep 2018 17:57:29 +0000 (13:57 -0400)
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

doc/build/changelog/unreleased_12/pr472.rst [new file with mode: 0644]
lib/sqlalchemy/orm/state.py

diff --git a/doc/build/changelog/unreleased_12/pr472.rst b/doc/build/changelog/unreleased_12/pr472.rst
new file mode 100644 (file)
index 0000000..baa5741
--- /dev/null
@@ -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.
index 70420ca5099057c07c87aeb3f25294f79eb44afb..03d68ab820c1b1d42d69af4b703827be2c3eb174 100644 (file)
@@ -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)