Skip to content

Commit

Permalink
Look for dict builtin in InstanceState cleanup
Browse files Browse the repository at this point in the history
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: #472
  • Loading branch information
romuald authored and zzzeek committed Sep 18, 2018
1 parent 67a2cd9 commit 5059412
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/build/changelog/unreleased_12/pr472.rst
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions lib/sqlalchemy/orm/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ def _cleanup(self, ref):
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)
Expand Down

0 comments on commit 5059412

Please sign in to comment.