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
--- /dev/null
+.. 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.
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)