]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Pre-load alias.c within JoinedEagerLoader cached AliasedClass
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 26 Mar 2017 02:17:17 +0000 (22:17 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 26 Mar 2017 02:18:51 +0000 (22:18 -0400)
Fixed a race condition which could occur under threaded environments
as a result of the caching added via :ticket:`3915`.   An internal
collection of ``Column`` objects could be regenerated on an alias
object inappropriately, confusing a joined eager loader when it
attempts to render SQL and collect results and resulting in an
attribute error.   The collection is now generated up front before
the alias object is cached and shared among threads.

Change-Id: I97d5b205992d38af8d2b4307178a15c086ef9993
Fixes: #3947
(cherry picked from commit f214f4d4f46de24008c63f2e034329a64f510833)

doc/build/changelog/changelog_11.rst
lib/sqlalchemy/orm/strategies.py

index 9d43d3ae163436a698601b1b9785808fe6dc810e..c60550923d838e20655b761faa525aeb713ea971 100644 (file)
 .. changelog::
     :version: 1.1.7
 
+    .. change::
+        :tags: bug, orm
+        :tickets: 3947
+        :versions: 1.2.0b1
+
+        Fixed a race condition which could occur under threaded environments
+        as a result of the caching added via :ticket:`3915`.   An internal
+        collection of ``Column`` objects could be regenerated on an alias
+        object inappropriately, confusing a joined eager loader when it
+        attempts to render SQL and collect results and resulting in an
+        attribute error.   The collection is now generated up front before
+        the alias object is cached and shared among threads.
+
     .. change::
         :tags: bug, sql, postgresql
         :tickets: 2892
index caf0da340160c6e24b9ab0c1b944ea95c78a818b..c70994e8f0f11427f76d33ea8ae40f0f1658c242 100644 (file)
@@ -1309,6 +1309,10 @@ class JoinedLoader(AbstractRelationshipLoader):
                 self.mapper,
                 flat=True,
                 use_mapper_path=True)
+            # load up the .columns collection on the Alias() before
+            # the object becomes shared among threads.  this prevents
+            # races for column identities.
+            inspect(to_adapt).selectable.c
 
             self._aliased_class_pool.append(to_adapt)