summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-12-15 21:44:00 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2015-12-15 21:44:00 -0500
commita22b2085068f860d05dbb98631d2ac2079a12b39 (patch)
tree3bebf7734ef7947b070b119b4dd86fbebbaab0d5
parent8a24da6c10e31b885708215b66c561e3302b0e63 (diff)
downloadsqlalchemy-a22b2085068f860d05dbb98631d2ac2079a12b39.tar.gz
- Fixed bug in baked loader system where the systemwide monkeypatch
for setting up baked lazy loaders would interfere with other loader strategies that rely on lazy loading as a fallback, e.g. joined and subquery eager loaders, leading to ``IndexError`` exceptions at mapper configuration time. fixes #3612
-rw-r--r--doc/build/changelog/changelog_10.rst11
-rw-r--r--lib/sqlalchemy/ext/baked.py3
-rw-r--r--lib/sqlalchemy/orm/interfaces.py6
-rw-r--r--test/ext/test_baked.py18
4 files changed, 36 insertions, 2 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst
index ab261c615..b9eae73e6 100644
--- a/doc/build/changelog/changelog_10.rst
+++ b/doc/build/changelog/changelog_10.rst
@@ -19,6 +19,17 @@
:version: 1.0.11
.. change::
+ :tags: bug, ext
+ :tickets: 3612
+ :versions: 1.1.0b1
+
+ Fixed bug in baked loader system where the systemwide monkeypatch
+ for setting up baked lazy loaders would interfere with other
+ loader strategies that rely on lazy loading as a fallback, e.g.
+ joined and subquery eager loaders, leading to ``IndexError``
+ exceptions at mapper configuration time.
+
+ .. change::
:tags: bug, orm
:tickets: 3611
:versions: 1.1.0b1
diff --git a/lib/sqlalchemy/ext/baked.py b/lib/sqlalchemy/ext/baked.py
index eb0c36805..d255b5ee4 100644
--- a/lib/sqlalchemy/ext/baked.py
+++ b/lib/sqlalchemy/ext/baked.py
@@ -384,7 +384,6 @@ def bake_lazy_loaders():
Python overhead for these operations.
"""
- strategies.LazyLoader._strategy_keys[:] = []
BakedLazyLoader._strategy_keys[:] = []
properties.RelationshipProperty.strategy_for(
@@ -394,6 +393,8 @@ def bake_lazy_loaders():
properties.RelationshipProperty.strategy_for(
lazy="baked_select")(BakedLazyLoader)
+ strategies.LazyLoader._strategy_keys[:] = BakedLazyLoader._strategy_keys[:]
+
def unbake_lazy_loaders():
"""Disable the use of baked queries for all lazyloaders systemwide.
diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py
index ed8f27332..e9ad75e31 100644
--- a/lib/sqlalchemy/orm/interfaces.py
+++ b/lib/sqlalchemy/orm/interfaces.py
@@ -493,7 +493,11 @@ class StrategizedProperty(MapperProperty):
return strategy
def _get_strategy_by_cls(self, cls):
- return self._get_strategy(cls._strategy_keys[0])
+ try:
+ return self._get_strategy(cls._strategy_keys[0])
+ except IndexError:
+ import pdb
+ pdb.set_trace()
def setup(
self, context, entity, path, adapter, **kwargs):
diff --git a/test/ext/test_baked.py b/test/ext/test_baked.py
index 740689d60..8bfa58403 100644
--- a/test/ext/test_baked.py
+++ b/test/ext/test_baked.py
@@ -717,6 +717,24 @@ class LazyLoaderTest(BakedTest):
u1._sa_instance_state
)
+ def test_systemwide_loaders_loadable_via_lazyloader(self):
+ from sqlalchemy.orm import configure_mappers
+ from sqlalchemy.orm.strategies import LazyLoader
+
+ baked.bake_lazy_loaders()
+ try:
+ User, Address = self._o2m_fixture(lazy='joined')
+
+ configure_mappers()
+
+ is_(
+ User.addresses.property.
+ _get_strategy_by_cls(LazyLoader).__class__,
+ BakedLazyLoader
+ )
+ finally:
+ baked.unbake_lazy_loaders()
+
def test_invocation_systemwide_loaders(self):
baked.bake_lazy_loaders()
try: