]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Protect against cls weakref becoming None
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 8 May 2017 22:36:57 +0000 (18:36 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 8 May 2017 22:36:57 +0000 (18:36 -0400)
Protected against testing "None" as a class in the case where
declarative classes are being garbage collected and new
automap prepare() operations are taking place concurrently, very
infrequently hitting a weakref that has not been fully acted upon
after gc.

Change-Id: I32e1dfc5ac46bac4127fe808cfd18368e2fad9dd

doc/build/changelog/changelog_11.rst
lib/sqlalchemy/ext/automap.py
lib/sqlalchemy/ext/declarative/base.py

index 3f0df74c9e374aca6fed0f9b0b032fc29febc640..2a44a2f1007ee87392a2a710767f4c261ff5f67a 100644 (file)
 .. changelog::
     :version: 1.1.10
 
+    .. change:: 3980
+        :tags: bug, ext
+        :versions: 1.2.0b1
+        :tickets: 3980
+
+        Protected against testing "None" as a class in the case where
+        declarative classes are being garbage collected and new
+        automap prepare() operations are taking place concurrently, very
+        infrequently hitting a weakref that has not been fully acted upon
+        after gc.
+
     .. change:: 3966
         :tags: bug, mysql
         :versions: 1.2.0b1
index 14599fe5e559a36c275ccea56e878ebf0067e22c..bd33ebde9fa01d5ab3af0db891c8c3cc580fb563 100644 (file)
@@ -877,9 +877,9 @@ def _relationships_for_fks(automap_base, map_config, table_to_map_config,
                            name_for_collection_relationship,
                            generate_relationship):
     local_table = map_config.local_table
-    local_cls = map_config.cls
+    local_cls = map_config.cls  # derived from a weakref, may be None
 
-    if local_table is None:
+    if local_table is None or local_cls is None:
         return
     for constraint in local_table.constraints:
         if isinstance(constraint, ForeignKeyConstraint):
index 3beee31910cc077fedd448fdc8c89edea09e2e7f..95f02ea9688f6557add5ddc957795eccecd6a499 100644 (file)
@@ -568,8 +568,12 @@ class _DeferredMapperConfig(_MapperConfig):
 
     @classmethod
     def classes_for_base(cls, base_cls, sort=True):
-        classes_for_base = [m for m in cls._configs.values()
-                            if issubclass(m.cls, base_cls)]
+        classes_for_base = [
+            m for m, cls_ in
+            [(m, m.cls) for m in cls._configs.values()]
+            if cls_ is not None and issubclass(cls_, base_cls)
+        ]
+
         if not sort:
             return classes_for_base