From: Mike Bayer Date: Mon, 24 Feb 2014 17:52:12 +0000 (-0500) Subject: - Fixed regression from 0.8 where using an option like X-Git-Tag: rel_0_9_4~110 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d966920b3df253292a28f2a57bef0d90afd66352;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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. --- diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index bbd843cb15..795fc3a0a6 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -14,6 +14,15 @@ .. 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 diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py index 6e838ccb79..e290e65976 100644 --- a/lib/sqlalchemy/orm/strategy_options.py +++ b/lib/sqlalchemy/orm/strategy_options.py @@ -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 diff --git a/test/orm/test_default_strategies.py b/test/orm/test_default_strategies.py index b1175fc512..a127f2ba5d 100644 --- a/test/orm/test_default_strategies.py +++ b/test/orm/test_default_strategies.py @@ -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