summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql/test_compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-09-18 13:29:42 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-09-18 22:35:48 -0400
commitf0f08db5715e41cc08e57dbc76a85300bd68f8de (patch)
tree3d17072c461927f5a66c654d3e824a24b949905b /test/dialect/postgresql/test_compiler.py
parentd5c89a541f5233baf6b6a7498746820caa7b407f (diff)
downloadsqlalchemy-f0f08db5715e41cc08e57dbc76a85300bd68f8de.tar.gz
Complete deprecation of from_self()
For most from_self() tests, move them into test/orm/test_deprecated.py and replace the existing test with one that uses aliased() plus a subquery. This then revealed a few more issues. Related items: * Added slice() method to GenerativeSelect, to match that of orm.Query and to make possible migration of one of the from_self() tests. moved the utility functions used for this from orm/util into sql/util. * repairs a caching issue related to subqueryload where information being derived from the cached path info was mixing up with query information based on the per-query state, specifically an AliasedClass that is per query. * for the above issue, it seemed like path_registry maybe had to change so that it represents AliasedClass objects as their cache key rather than on identity, but it wasn't needed. still seems like it would be more correct. * enhances the error message raised by coercions for a case such as when an AliasedClass holds onto a select() object and not a subquery(); will name the original and resolved object for clarity (although how is AliasedClass able to accept a Select() object in the first place?) * Added _set_propagate_attrs() to Query so that again if it's passed to AliasedClass, it doesn't raise an error during coercion, but again maybe that should also be rejected up front Fixes: #5368 Change-Id: I5912aa611d899acc87a75eb5ee9f95990592f210
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r--test/dialect/postgresql/test_compiler.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py
index 2dd64d9bc..64e945124 100644
--- a/test/dialect/postgresql/test_compiler.py
+++ b/test/dialect/postgresql/test_compiler.py
@@ -2243,12 +2243,15 @@ class DistinctOnTest(fixtures.TestBase, AssertsCompiledSQL):
mapper(Foo, self.table)
sess = Session()
+ subq = sess.query(Foo).subquery()
+
+ f1 = aliased(Foo, subq)
self.assert_compile(
- sess.query(Foo).from_self().distinct(Foo.a, Foo.b),
- "SELECT DISTINCT ON (anon_1.t_a, anon_1.t_b) anon_1.t_id "
- "AS anon_1_t_id, anon_1.t_a AS anon_1_t_a, anon_1.t_b "
- "AS anon_1_t_b FROM (SELECT t.id AS t_id, t.a AS t_a, "
- "t.b AS t_b FROM t) AS anon_1",
+ sess.query(f1).distinct(f1.a, f1.b),
+ "SELECT DISTINCT ON (anon_1.a, anon_1.b) anon_1.id "
+ "AS anon_1_id, anon_1.a AS anon_1_a, anon_1.b "
+ "AS anon_1_b FROM (SELECT t.id AS id, t.a AS a, "
+ "t.b AS b FROM t) AS anon_1",
)
def test_query_distinct_on_aliased(self):