]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed regression from 0.8 where using an option like
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 24 Feb 2014 17:52:12 +0000 (12:52 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 24 Feb 2014 17:52:12 +0000 (12:52 -0500)
:func:`.orm.lazyload` with the "wildcard" expression, e.g. ``"*"``,
would raise an assertion error in the case where the query didn't
contain any actual entities.  This assertion is meant for other cases
and was catching this one inadvertently.

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/orm/strategy_options.py
test/orm/test_default_strategies.py

index bbd843cb1552d008bee085fdf268b15a7f2c02f6..795fc3a0a65c7f577b17a5f3fab40ee97b837806 100644 (file)
 .. changelog::
     :version: 0.9.4
 
+    .. change::
+        :tags: bug, orm
+
+        Fixed regression from 0.8 where using an option like
+        :func:`.orm.lazyload` with the "wildcard" expression, e.g. ``"*"``,
+        would raise an assertion error in the case where the query didn't
+        contain any actual entities.  This assertion is meant for other cases
+        and was catching this one inadvertently.
+
     .. change::
         :tags: bug, examples
 
index 6e838ccb792d91ba24289babd7df2fefd4c3db1a..e290e65976d9553665aae6120bc312ab4113cc43 100644 (file)
@@ -431,6 +431,8 @@ class _UnboundLoad(Load):
                             "Wildcard loader can only be used with exactly "
                             "one entity.  Use Load(ent) to specify "
                             "specific entities.")
+        elif token.endswith(_DEFAULT_TOKEN):
+            raiseerr = False
 
         for ent in query._mapper_entities:
             # return only the first _MapperEntity when searching
index b1175fc512b6ccf49a3b8adcb05976ad5624ce7b..a127f2ba5d4ba1036040a67fb6bb4c959cc0d956 100644 (file)
@@ -156,6 +156,20 @@ class DefaultStrategyOptionsTest(_fixtures.FixtureTest):
             sess.query(User).options, opt
         )
 
+    def test_global_star_ignored_no_entities_unbound(self):
+        sess = self._downgrade_fixture()
+        User = self.classes.User
+        opt = sa.orm.lazyload('*')
+        q = sess.query(User.name).options(opt)
+        eq_(q.all(), [(u'jack',), (u'ed',), (u'fred',), (u'chuck',)])
+
+    def test_global_star_ignored_no_entities_bound(self):
+        sess = self._downgrade_fixture()
+        User = self.classes.User
+        opt = sa.orm.Load(User).lazyload('*')
+        q = sess.query(User.name).options(opt)
+        eq_(q.all(), [(u'jack',), (u'ed',), (u'fred',), (u'chuck',)])
+
     def test_select_with_joinedload(self):
         """Mapper load strategy defaults can be downgraded with
         lazyload('*') option, while explicit joinedload() option