summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/state.py
diff options
context:
space:
mode:
authorRomuald Brunet <romuald@gandi.net>2018-09-17 11:44:50 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2018-09-18 13:57:29 -0400
commit505941259e4e7181a176e74b3de0b7d96c444e29 (patch)
tree7ec7a57c631ff17f611a50883a0bac1eff3b3fc1 /lib/sqlalchemy/orm/state.py
parent67a2cd92295bef55d914a5c560b4cead5d456837 (diff)
downloadsqlalchemy-505941259e4e7181a176e74b3de0b7d96c444e29.tar.gz
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
Diffstat (limited to 'lib/sqlalchemy/orm/state.py')
-rw-r--r--lib/sqlalchemy/orm/state.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py
index 70420ca50..03d68ab82 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)