diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-08-29 14:01:38 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-08-29 14:01:38 -0400 |
| commit | eb8a39c58cf3ef8f43d9bead3a534b5700f4a519 (patch) | |
| tree | 688d7a50463ca4c5d1f7c5b0a048a613602f8d39 /test/orm | |
| parent | faf319fff51388c684d29ffc80f199c0f8f79708 (diff) | |
| download | sqlalchemy-eb8a39c58cf3ef8f43d9bead3a534b5700f4a519.tar.gz | |
- The :class:`.Query` will raise an exception when :meth:`.Query.yield_per`
is used with mappings or options where eager loading, either
joined or subquery, would take place. These loading strategies are
not currently compatible with yield_per, so by raising this error,
the method is safer to use - combine with sending False to
:meth:`.Query.enable_eagerloads` to disable the eager loaders.
Diffstat (limited to 'test/orm')
| -rw-r--r-- | test/orm/test_query.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/test/orm/test_query.py b/test/orm/test_query.py index 984a3f93f..6ac1ba5af 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -6,7 +6,8 @@ from sqlalchemy.sql import operators, column, expression from sqlalchemy.engine import default from sqlalchemy.orm import ( attributes, mapper, relationship, create_session, synonym, Session, - aliased, column_property, joinedload_all, joinedload, Query, Bundle) + aliased, column_property, joinedload_all, joinedload, Query, Bundle, + subqueryload) from sqlalchemy.testing.assertsql import CompiledSQL from sqlalchemy.testing.schema import Table, Column import sqlalchemy as sa @@ -2147,6 +2148,39 @@ class YieldTest(QueryTest): assert q._yield_per eq_(q._execution_options, {"stream_results": True, "foo": "bar"}) + def test_no_joinedload(self): + User = self.classes.User + sess = create_session() + q = sess.query(User).options(joinedload("addresses")).yield_per(1) + assert_raises_message( + sa_exc.InvalidRequestError, + "The yield_per Query option is currently not compatible with " + "joined eager loading. Please specify ", + q.all + ) + + def test_no_subqueryload(self): + User = self.classes.User + sess = create_session() + q = sess.query(User).options(subqueryload("addresses")).yield_per(1) + assert_raises_message( + sa_exc.InvalidRequestError, + "The yield_per Query option is currently not compatible with " + "subquery eager loading. Please specify ", + q.all + ) + + def test_eagerload_disable(self): + User = self.classes.User + sess = create_session() + q = sess.query(User).options(subqueryload("addresses")).\ + enable_eagerloads(False).yield_per(1) + q.all() + + q = sess.query(User).options(joinedload("addresses")).\ + enable_eagerloads(False).yield_per(1) + q.all() + class HintsTest(QueryTest, AssertsCompiledSQL): def test_hints(self): |
