]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed an unlikely race condition observed in some exotic end-user
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 18 Sep 2014 19:42:27 +0000 (15:42 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 18 Sep 2014 19:42:27 +0000 (15:42 -0400)
setups, where the attempt to check for "duplicate class name" in
declarative would hit upon a not-totally-cleaned-up weak reference
related to some other class being removed; the check here now ensures
the weakref still references an object before calling upon it further.
fixes #3208

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/ext/declarative/clsregistry.py

index 56be5b38e7f3e572ab98d694b93468a9f6c93225..c0d13e16db5b5a6015fcd1239a609b9e5a0a9c0e 100644 (file)
 .. changelog::
     :version: 0.9.8
 
+    .. change::
+        :tags: bug, declarative
+        :versions: 1.0.0
+        :tickets: 3208
+
+        Fixed an unlikely race condition observed in some exotic end-user
+        setups, where the attempt to check for "duplicate class name" in
+        declarative would hit upon a not-totally-cleaned-up weak reference
+        related to some other class being removed; the check here now ensures
+        the weakref still references an object before calling upon it further.
+
     .. change::
         :tags: bug, orm
         :versions: 1.0.0
index 4595b857a80af62134cacf894fc948ef5544347a..3ef63a5aeb7f8fd4370bbb3fc9455650ee405162 100644 (file)
@@ -103,7 +103,12 @@ class _MultipleClassMarker(object):
                 self.on_remove()
 
     def add_item(self, item):
-        modules = set([cls().__module__ for cls in self.contents])
+        # protect against class registration race condition against
+        # asynchronous garbage collection calling _remove_item,
+        # [ticket:3208]
+        modules = set([
+            cls.__module__ for cls in
+            [ref() for ref in self.contents] if cls is not None])
         if item.__module__ in modules:
             util.warn(
                 "This declarative base already contains a class with the "