diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-01-17 23:38:40 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-01-18 21:48:20 -0500 |
| commit | 1c56b6049a3fdd1122a4c82ae5757332d3753146 (patch) | |
| tree | 2a6f9f5530e78409bd44d5d7175ed0fcff3190fe /test | |
| parent | 265644072e5ae4cd0aadf94e5e6ca060f8d8c66f (diff) | |
| download | sqlalchemy-1c56b6049a3fdd1122a4c82ae5757332d3753146.tar.gz | |
Cleanup with query aliasing
Try to simplify some of the "adapter" stuff in query:
1. identify that join(.., aliased=True) doesn't work if the
right side has no mapper. The adaption of the right side is
done via the mapper with aliased(), so that doesn't effect
a selectable only. raise an error, so we can simplify
the code.
2. build fewer adapter objects. these are confusing to follow
and we should try to figure out exactly what purpose which
one serves where and make that clear.
Change-Id: I18dfcd01e6ad533aa0b8d557fc637ee2766ed050
Diffstat (limited to 'test')
| -rw-r--r-- | test/orm/test_froms.py | 2 | ||||
| -rw-r--r-- | test/orm/test_joins.py | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/test/orm/test_froms.py b/test/orm/test_froms.py index 9b68136bd..fc2fb670c 100644 --- a/test/orm/test_froms.py +++ b/test/orm/test_froms.py @@ -3555,7 +3555,7 @@ class TestOverlyEagerEquivalentCols(fixtures.MappedTest): sess.flush() q = sess.query(Base).outerjoin("sub2", aliased=True) - assert sub1.c.id not in q._filter_aliases.equivalents + assert sub1.c.id not in q._filter_aliases[0].equivalents eq_( sess.query(Base) diff --git a/test/orm/test_joins.py b/test/orm/test_joins.py index 5aefe61cc..046d5c3e2 100644 --- a/test/orm/test_joins.py +++ b/test/orm/test_joins.py @@ -2588,6 +2588,27 @@ class JoinFromSelectableTest(fixtures.MappedTest, AssertsCompiledSQL): "ON anon_1.t1_id = table1.id", ) + def test_mapped_to_select_implicit_left_w_aliased(self): + T1, T2 = self.classes.T1, self.classes.T2 + + sess = Session() + subq = ( + sess.query(T2.t1_id, func.count(T2.id).label("count")) + .group_by(T2.t1_id) + .subquery() + ) + + assert_raises_message( + sa_exc.InvalidRequestError, + r"The aliased=True parameter on query.join\(\) only works with " + "an ORM entity, not a plain selectable, as the target.", + # this doesn't work, so have it raise an error + sess.query(T1.id).join, + subq, + subq.c.t1_id == T1.id, + aliased=True, + ) + class MultiplePathTest(fixtures.MappedTest, AssertsCompiledSQL): @classmethod |
