summaryrefslogtreecommitdiff
path: root/test/orm
diff options
context:
space:
mode:
authorGord Thompson <gord@gordthompson.com>2021-01-09 14:56:38 -0700
committerMike Bayer <mike_mp@zzzcomputing.com>2021-01-26 16:52:30 -0500
commit22f65156bbe846dea2fb9f87fe4187abe0ed790a (patch)
treef49338a10dd2800d4d754b14d2e7fd549b4b833f /test/orm
parent7bdb1f30f66aaea16efbcf96e314491058493e6c (diff)
downloadsqlalchemy-22f65156bbe846dea2fb9f87fe4187abe0ed790a.tar.gz
Replace with_labels() and apply_labels() in ORM/Core
Replace :meth:`_orm.Query.with_labels` and :meth:`_sql.GenerativeSelect.apply_labels` with explicit getters and setters ``get_label_style`` and ``set_label_style`` to accommodate the three supported label styles: ``LABEL_STYLE_DISAMBIGUATE_ONLY`` (default), ``LABEL_STYLE_TABLENAME_PLUS_COL``, and ``LABEL_STYLE_NONE``. In addition, for Core and "future style" ORM queries, ``LABEL_STYLE_DISAMBIGUATE_ONLY`` is now the default label style. This style differs from the existing "no labels" style in that labeling is applied in the case of column name conflicts; with ``LABEL_STYLE_NONE``, a duplicate column name is not accessible via name in any case. For legacy ORM queries using :class:`_query.Query`, the table-plus-column names labeling style applied by ``LABEL_STYLE_TABLENAME_PLUS_COL`` continues to be used so that existing test suites and logging facilities see no change in behavior by default, however this style of labeling is no longer required for SQLAlchemy queries to function, as result sets are commonly matched to columns using a positional approach since SQLAlchemy 1.0. Within test suites, all use of apply_labels() / use_labels now uses the new methods. New tests added to test/sql/test_deprecations.py nad test/orm/test_deprecations.py to cover just the old apply_labels() method call. Tests in ORM that made explicit use apply_labels()/ etc. where it isn't needed for the ORM to work correctly use default label style now. Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Fixes: #4757 Change-Id: I5fdcd2ed4ae8c7fe62f8be2b6d0e8f66409b6a54
Diffstat (limited to 'test/orm')
-rw-r--r--test/orm/inheritance/_poly_fixtures.py4
-rw-r--r--test/orm/inheritance/test_basic.py6
-rw-r--r--test/orm/inheritance/test_concrete.py3
-rw-r--r--test/orm/inheritance/test_poly_loading.py3
-rw-r--r--test/orm/inheritance/test_polymorphic_rel.py1
-rw-r--r--test/orm/inheritance/test_relationship.py74
-rw-r--r--test/orm/inheritance/test_single.py14
-rw-r--r--test/orm/test_deprecations.py72
-rw-r--r--test/orm/test_eager_relations.py14
-rw-r--r--test/orm/test_froms.py122
-rw-r--r--test/orm/test_joins.py7
-rw-r--r--test/orm/test_lambdas.py11
-rw-r--r--test/orm/test_lazy_relations.py10
-rw-r--r--test/orm/test_query.py120
14 files changed, 266 insertions, 195 deletions
diff --git a/test/orm/inheritance/_poly_fixtures.py b/test/orm/inheritance/_poly_fixtures.py
index 7a70810a1..7efc99913 100644
--- a/test/orm/inheritance/_poly_fixtures.py
+++ b/test/orm/inheritance/_poly_fixtures.py
@@ -428,14 +428,14 @@ class _PolymorphicAliasedJoins(_PolymorphicFixtureBase):
people.outerjoin(engineers)
.outerjoin(managers)
.select()
- ._set_label_style(cls.label_style)
+ .set_label_style(cls.label_style)
.subquery("pjoin")
)
manager_join = (
people.join(managers)
.outerjoin(boss)
.select()
- ._set_label_style(cls.label_style)
+ .set_label_style(cls.label_style)
.subquery("mjoin")
)
person_with_polymorphic = ([Person, Manager, Engineer], person_join)
diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py
index da07b4941..d145fef79 100644
--- a/test/orm/inheritance/test_basic.py
+++ b/test/orm/inheritance/test_basic.py
@@ -29,6 +29,7 @@ from sqlalchemy.orm import relationship
from sqlalchemy.orm import Session
from sqlalchemy.orm import synonym
from sqlalchemy.orm.util import instance_str
+from sqlalchemy.sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL
from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import eq_
@@ -2589,7 +2590,10 @@ class OptimizedLoadTest(fixtures.MappedTest):
polymorphic_identity="sub",
with_polymorphic=(
"*",
- base.outerjoin(sub).select().apply_labels().alias("foo"),
+ base.outerjoin(sub)
+ .select()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
+ .alias("foo"),
),
)
sess = fixture_session()
diff --git a/test/orm/inheritance/test_concrete.py b/test/orm/inheritance/test_concrete.py
index f2f8d629b..de0c72f68 100644
--- a/test/orm/inheritance/test_concrete.py
+++ b/test/orm/inheritance/test_concrete.py
@@ -443,7 +443,7 @@ class ConcreteTest(fixtures.MappedTest):
assert (
len(
session.connection()
- .execute(session.query(Employee).with_labels().statement)
+ .execute(session.query(Employee).statement)
.fetchall()
)
== 3
@@ -521,7 +521,6 @@ class ConcreteTest(fixtures.MappedTest):
.execute(
session.query(Employee)
.with_polymorphic("*", pjoin, pjoin.c.type)
- .with_labels()
.statement
)
.fetchall()
diff --git a/test/orm/inheritance/test_poly_loading.py b/test/orm/inheritance/test_poly_loading.py
index 2f31ab0c4..35822a29e 100644
--- a/test/orm/inheritance/test_poly_loading.py
+++ b/test/orm/inheritance/test_poly_loading.py
@@ -10,6 +10,7 @@ from sqlalchemy.orm import selectin_polymorphic
from sqlalchemy.orm import selectinload
from sqlalchemy.orm import Session
from sqlalchemy.orm import with_polymorphic
+from sqlalchemy.sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
from sqlalchemy.testing.assertsql import AllOf
@@ -434,7 +435,7 @@ class TestGeometries(GeometryFixtureBase):
.select_from(
a_table.join(c_table).outerjoin(d_table).outerjoin(e_table)
)
- .apply_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.alias("poly")
)
diff --git a/test/orm/inheritance/test_polymorphic_rel.py b/test/orm/inheritance/test_polymorphic_rel.py
index 581fa45fd..de7723125 100644
--- a/test/orm/inheritance/test_polymorphic_rel.py
+++ b/test/orm/inheritance/test_polymorphic_rel.py
@@ -156,7 +156,6 @@ class _PolymorphicTestBase(object):
.order_by(Person.person_id)
.limit(2)
.offset(1)
- .with_labels()
.subquery()
)
),
diff --git a/test/orm/inheritance/test_relationship.py b/test/orm/inheritance/test_relationship.py
index 214be5e9a..d983ddac9 100644
--- a/test/orm/inheritance/test_relationship.py
+++ b/test/orm/inheritance/test_relationship.py
@@ -16,6 +16,7 @@ from sqlalchemy.orm import Session
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import subqueryload
from sqlalchemy.orm import with_polymorphic
+from sqlalchemy.sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL
from sqlalchemy.testing import AssertsCompiledSQL
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
@@ -728,8 +729,10 @@ class SelfReferentialM2MTest(fixtures.MappedTest, AssertsCompiledSQL):
sess.flush()
# test that the join to Child2 doesn't alias Child1 in the select
+
+ stmt = select(Child1).join(Child1.left_child2)
eq_(
- set(sess.query(Child1).join(Child1.left_child2)),
+ set(sess.execute(stmt).scalars().unique()),
set([c11, c12, c13]),
)
@@ -739,12 +742,14 @@ class SelfReferentialM2MTest(fixtures.MappedTest, AssertsCompiledSQL):
)
# test __eq__() on property is annotating correctly
+
+ stmt = (
+ select(Child2)
+ .join(Child2.right_children)
+ .where(Child1.left_child2 == c22)
+ )
eq_(
- set(
- sess.query(Child2)
- .join(Child2.right_children)
- .filter(Child1.left_child2 == c22)
- ),
+ set(sess.execute(stmt).scalars().unique()),
set([c22]),
)
@@ -753,17 +758,16 @@ class SelfReferentialM2MTest(fixtures.MappedTest, AssertsCompiledSQL):
sess.query(Child2)
.join(Child2.right_children)
.filter(Child1.left_child2 == c22)
- .with_labels()
.statement,
- "SELECT child2.id AS child2_id, parent.id AS parent_id, "
- "parent.cls AS parent_cls FROM secondary AS secondary_1, "
- "parent JOIN child2 ON parent.id = child2.id JOIN secondary AS "
- "secondary_2 ON parent.id = secondary_2.left_id JOIN "
- "(parent AS parent_1 JOIN child1 AS child1_1 "
- "ON parent_1.id = child1_1.id) "
- "ON parent_1.id = secondary_2.right_id WHERE "
- "parent_1.id = secondary_1.right_id AND :param_1 = "
- "secondary_1.left_id",
+ "SELECT child2.id, parent.id AS id_1, parent.cls "
+ "FROM secondary AS secondary_1, parent "
+ "JOIN child2 ON parent.id = child2.id "
+ "JOIN secondary AS secondary_2 ON parent.id = secondary_2.left_id "
+ "JOIN (parent AS parent_1 JOIN child1 AS child1_1 "
+ "ON parent_1.id = child1_1.id) ON parent_1.id = "
+ "secondary_2.right_id "
+ "WHERE parent_1.id = secondary_1.right_id "
+ "AND :param_1 = secondary_1.left_id",
)
def test_query_crit_core_workaround(self):
@@ -797,7 +801,7 @@ class SelfReferentialM2MTest(fixtures.MappedTest, AssertsCompiledSQL):
)
self.assert_compile(
- stmt.apply_labels(),
+ stmt.set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL),
"SELECT child2.id AS child2_id, parent.id AS parent_id, "
"parent.cls AS parent_cls "
"FROM secondary AS secondary_1, "
@@ -822,16 +826,14 @@ class SelfReferentialM2MTest(fixtures.MappedTest, AssertsCompiledSQL):
# the middle of "parent join child1"
q = sess.query(Child1).options(joinedload("left_child2"))
self.assert_compile(
- q.limit(1).with_labels().statement,
- "SELECT child1.id AS child1_id, parent.id AS parent_id, "
- "parent.cls AS parent_cls, child2_1.id AS child2_1_id, "
- "parent_1.id AS parent_1_id, parent_1.cls AS parent_1_cls "
+ q.limit(1).statement,
+ "SELECT child1.id, parent.id AS id_1, parent.cls, "
+ "child2_1.id AS id_2, parent_1.id AS id_3, parent_1.cls AS cls_1 "
"FROM parent JOIN child1 ON parent.id = child1.id "
- "LEFT OUTER JOIN (secondary AS secondary_1 JOIN "
- "(parent AS parent_1 JOIN child2 AS child2_1 "
- "ON parent_1.id = child2_1.id) "
- "ON parent_1.id = secondary_1.left_id) "
- "ON parent.id = secondary_1.right_id "
+ "LEFT OUTER JOIN (secondary AS secondary_1 "
+ "JOIN (parent AS parent_1 JOIN child2 AS child2_1 "
+ "ON parent_1.id = child2_1.id) ON parent_1.id = "
+ "secondary_1.left_id) ON parent.id = secondary_1.right_id "
"LIMIT :param_1",
checkparams={"param_1": 1},
)
@@ -839,9 +841,7 @@ class SelfReferentialM2MTest(fixtures.MappedTest, AssertsCompiledSQL):
# another way to check
eq_(
sess.scalar(
- select(func.count("*")).select_from(
- q.limit(1).with_labels().subquery()
- )
+ select(func.count("*")).select_from(q.limit(1).subquery())
),
1,
)
@@ -1761,9 +1761,17 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest):
stmt = select(Sub2)
- subq = aliased(Sub2, stmt.apply_labels().subquery())
+ subq = aliased(
+ Sub2,
+ stmt.set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL).subquery(),
+ )
- stmt = select(subq).join(subq.ep1).join(Sub2.ep2).apply_labels()
+ stmt = (
+ select(subq)
+ .join(subq.ep1)
+ .join(Sub2.ep2)
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
+ )
self.assert_compile(
stmt,
"SELECT anon_1.sub2_id AS anon_1_sub2_id, "
@@ -1832,7 +1840,7 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest):
select(Parent, Sub2)
.join(Parent.sub1)
.join(Sub1.sub2)
- .apply_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.subquery()
)
@@ -1845,7 +1853,7 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest):
select(palias, sub2alias)
.join(sub2alias.ep1)
.join(sub2alias.ep2)
- .apply_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
)
self.assert_compile(
diff --git a/test/orm/inheritance/test_single.py b/test/orm/inheritance/test_single.py
index 11c6bb212..ececaf882 100644
--- a/test/orm/inheritance/test_single.py
+++ b/test/orm/inheritance/test_single.py
@@ -18,6 +18,7 @@ from sqlalchemy.orm import relationship
from sqlalchemy.orm import Session
from sqlalchemy.orm import subqueryload
from sqlalchemy.orm import with_polymorphic
+from sqlalchemy.sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL
from sqlalchemy.testing import AssertsCompiledSQL
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
@@ -312,7 +313,10 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
Engineer = self.classes.Engineer
stmt = select(Engineer)
- subq = aliased(Engineer, stmt.apply_labels().subquery())
+ subq = aliased(
+ Engineer,
+ stmt.set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL).subquery(),
+ )
# so here we have an extra "WHERE type in ()", because
# both the inner and the outer queries have the Engineer entity.
@@ -321,7 +325,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
# legacy from_self() takes care of this because it applies
# _enable_single_crit at that moment.
- stmt = select(subq).apply_labels()
+ stmt = select(subq).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
self.assert_compile(
stmt,
"SELECT anon_1.employees_employee_id AS "
@@ -526,7 +530,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
),
)
)
- .apply_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.subquery()
)
eq_(
@@ -1638,7 +1642,7 @@ class SingleFromPolySelectableTest(
null().label("manager_id"),
)
.select_from(employee.join(manager))
- .apply_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.union_all(
select(
employee.c.id,
@@ -1649,7 +1653,7 @@ class SingleFromPolySelectableTest(
engineer.c.manager_id,
)
.select_from(employee.join(engineer))
- .apply_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
)
.alias()
)
diff --git a/test/orm/test_deprecations.py b/test/orm/test_deprecations.py
index 90bb291f8..e15bb4674 100644
--- a/test/orm/test_deprecations.py
+++ b/test/orm/test_deprecations.py
@@ -455,9 +455,7 @@ class DeprecatedQueryTest(_fixtures.FixtureTest, AssertsCompiledSQL):
.union(users.select(users.c.id > 7))
.alias("ulist")
.outerjoin(addresses)
- .select(
- use_labels=True, order_by=[text("ulist.id"), addresses.c.id]
- )
+ .select(order_by=[text("ulist.id"), addresses.c.id])
)
sess = fixture_session()
@@ -492,7 +490,7 @@ class DeprecatedQueryTest(_fixtures.FixtureTest, AssertsCompiledSQL):
.union(users.select(users.c.id > 7))
.alias("ulist")
.outerjoin(adalias)
- .select(use_labels=True, order_by=[text("ulist.id"), adalias.c.id])
+ .select(order_by=[text("ulist.id"), adalias.c.id])
)
def go():
@@ -513,16 +511,45 @@ class DeprecatedQueryTest(_fixtures.FixtureTest, AssertsCompiledSQL):
sess = fixture_session()
with self._expect_implicit_subquery():
- self.assert_compile(
- sess.query(users)
- .select_entity_from(users.select())
- .with_labels()
- .statement,
- "SELECT users.id AS users_id, users.name AS users_name "
- "FROM users, "
- "(SELECT users.id AS id, users.name AS name FROM users) "
- "AS anon_1",
- )
+ stmt = sess.query(users).select_entity_from(users.select())
+
+ with testing.expect_deprecated_20(r"The Query.with_labels\(\)"):
+ stmt = stmt.apply_labels().statement
+ self.assert_compile(
+ stmt,
+ "SELECT users.id AS users_id, users.name AS users_name "
+ "FROM users, "
+ "(SELECT users.id AS id, users.name AS name FROM users) "
+ "AS anon_1",
+ )
+
+ def test_apply_labels(self):
+ User = self.classes.User
+
+ with testing.expect_deprecated_20(
+ r"The Query.with_labels\(\) and Query.apply_labels\(\) "
+ "method is considered legacy"
+ ):
+ q = fixture_session().query(User).apply_labels().statement
+
+ self.assert_compile(
+ q,
+ "SELECT users.id AS users_id, users.name AS users_name FROM users",
+ )
+
+ def test_with_labels(self):
+ User = self.classes.User
+
+ with testing.expect_deprecated_20(
+ r"The Query.with_labels\(\) and Query.apply_labels\(\) "
+ "method is considered legacy"
+ ):
+ q = fixture_session().query(User).with_labels().statement
+
+ self.assert_compile(
+ q,
+ "SELECT users.id AS users_id, users.name AS users_name FROM users",
+ )
def test_join(self):
users, Address, User = (
@@ -3058,9 +3085,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
.union(users.select(users.c.id > 7))
.alias("ulist")
.outerjoin(addresses)
- .select(
- use_labels=True, order_by=[text("ulist.id"), addresses.c.id]
- )
+ .select(order_by=[text("ulist.id"), addresses.c.id])
)
sess = fixture_session()
q = sess.query(User)
@@ -3094,9 +3119,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
.union(users.select(users.c.id > 7))
.alias("ulist")
.outerjoin(addresses)
- .select(
- use_labels=True, order_by=[text("ulist.id"), addresses.c.id]
- )
+ .select(order_by=[text("ulist.id"), addresses.c.id])
)
sess = fixture_session()
q = sess.query(User)
@@ -3128,7 +3151,6 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
selectquery = users.outerjoin(addresses).select(
users.c.id < 10,
- use_labels=True,
order_by=[users.c.id, addresses.c.id],
)
q = sess.query(User)
@@ -3173,7 +3195,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
adalias = addresses.alias("adalias")
selectquery = users.outerjoin(adalias).select(
- use_labels=True, order_by=[users.c.id, adalias.c.id]
+ order_by=[users.c.id, adalias.c.id]
)
# note this has multiple problems because we aren't giving Query
@@ -3207,7 +3229,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
adalias = addresses.alias("adalias")
selectquery = users.outerjoin(adalias).select(
- use_labels=True, order_by=[users.c.id, adalias.c.id]
+ order_by=[users.c.id, adalias.c.id]
)
# note this has multiple problems because we aren't giving Query
@@ -3243,7 +3265,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
users.outerjoin(oalias)
.outerjoin(order_items)
.outerjoin(ialias)
- .select(use_labels=True)
+ .select()
.order_by(users.c.id, oalias.c.id, ialias.c.id)
)
@@ -3284,7 +3306,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
users.outerjoin(oalias)
.outerjoin(order_items)
.outerjoin(ialias)
- .select(use_labels=True)
+ .select()
.order_by(users.c.id, oalias.c.id, ialias.c.id)
)
diff --git a/test/orm/test_eager_relations.py b/test/orm/test_eager_relations.py
index 0f67aa94d..d575b85f1 100644
--- a/test/orm/test_eager_relations.py
+++ b/test/orm/test_eager_relations.py
@@ -28,6 +28,7 @@ from sqlalchemy.orm import relationship
from sqlalchemy.orm import Session
from sqlalchemy.orm import undefer
from sqlalchemy.sql import operators
+from sqlalchemy.sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL
from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import eq_
@@ -1081,9 +1082,9 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL):
# more rows.
u2 = users.alias("u2")
s = sa.union_all(
- u2.select(use_labels=True),
- u2.select(use_labels=True),
- u2.select(use_labels=True),
+ u2.select(),
+ u2.select(),
+ u2.select(),
).alias("u")
mapper(
@@ -1103,10 +1104,7 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL):
def go():
result = (
- q.filter(s.c.u2_id == User.id)
- .distinct()
- .order_by(User.id)
- .all()
+ q.filter(s.c.id == User.id).distinct().order_by(User.id).all()
)
eq_(self.static.user_address_result, result)
@@ -4791,7 +4789,7 @@ class MixedEntitiesTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL):
sess.query(User, oalias)
.join(User.orders)
.options(joinedload(oalias.items))
- .with_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.statement,
"SELECT users.id AS users_id, users.name AS users_name, "
"orders_1.id AS orders_1_id, "
diff --git a/test/orm/test_froms.py b/test/orm/test_froms.py
index f622bff02..1464cfc28 100644
--- a/test/orm/test_froms.py
+++ b/test/orm/test_froms.py
@@ -30,6 +30,7 @@ from sqlalchemy.orm import Session
from sqlalchemy.orm.util import join
from sqlalchemy.sql import column
from sqlalchemy.sql import table
+from sqlalchemy.sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL
from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import AssertsCompiledSQL
@@ -274,19 +275,26 @@ class QueryCorrelatesLikeSelect(QueryTest, AssertsCompiledSQL):
"FROM users) AS anon_1",
)
- def test_correlate_to_union_newstyle(self):
+ def test_correlate_to_union_w_labels_newstyle(self):
User = self.classes.User
- q = select(User).apply_labels()
+ q = select(User).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
- q = select(User).union(q).apply_labels().subquery()
+ q = (
+ select(User)
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
+ .union(q)
+ .subquery()
+ )
u_alias = aliased(User)
raw_subq = exists().where(u_alias.id > q.c[0])
self.assert_compile(
- select(q, raw_subq).apply_labels(),
+ select(q, raw_subq).set_label_style(
+ LABEL_STYLE_TABLENAME_PLUS_COL
+ ),
"SELECT anon_1.users_id AS anon_1_users_id, "
"anon_1.users_name AS anon_1_users_name, "
"EXISTS (SELECT * FROM users AS users_1 "
@@ -297,6 +305,27 @@ class QueryCorrelatesLikeSelect(QueryTest, AssertsCompiledSQL):
"FROM users) AS anon_1",
)
+ def test_correlate_to_union_newstyle(self):
+ User = self.classes.User
+
+ q = select(User)
+
+ q = select(User).union(q).subquery()
+
+ u_alias = aliased(User)
+
+ raw_subq = exists().where(u_alias.id > q.c[0])
+
+ self.assert_compile(
+ select(q, raw_subq),
+ "SELECT anon_1.id, anon_1.name, EXISTS "
+ "(SELECT * FROM users AS users_1 WHERE users_1.id > anon_1.id) "
+ "AS anon_2 FROM (SELECT users.id AS id, users.name AS name "
+ "FROM users "
+ "UNION SELECT users.id AS id, users.name AS name FROM users) "
+ "AS anon_1",
+ )
+
class RawSelectTest(QueryTest, AssertsCompiledSQL):
"""compare a bunch of select() tests with the equivalent Query using
@@ -317,7 +346,7 @@ class RawSelectTest(QueryTest, AssertsCompiledSQL):
self.assert_compile(
sess.query(users)
.select_entity_from(users.select().subquery())
- .with_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.statement,
"SELECT users.id AS users_id, users.name AS users_name "
"FROM users, "
@@ -326,7 +355,7 @@ class RawSelectTest(QueryTest, AssertsCompiledSQL):
self.assert_compile(
sess.query(users, exists([1], from_obj=addresses))
- .with_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.statement,
"SELECT users.id AS users_id, users.name AS users_name, EXISTS "
"(SELECT 1 FROM addresses) AS anon_1 FROM users",
@@ -347,7 +376,7 @@ class RawSelectTest(QueryTest, AssertsCompiledSQL):
self.assert_compile(
sess.query(users, s.c.email)
.select_entity_from(users.join(s, s.c.id == users.c.id))
- .with_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.statement,
"SELECT users.id AS users_id, users.name AS users_name, "
"anon_1.email AS anon_1_email "
@@ -480,7 +509,7 @@ class EntityFromSubqueryTest(QueryTest, AssertsCompiledSQL):
select(User.id)
.group_by(User.id)
.having(User.id > 5)
- .apply_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.subquery()
)
@@ -501,7 +530,7 @@ class EntityFromSubqueryTest(QueryTest, AssertsCompiledSQL):
subq = (
select(User)
.options(joinedload(User.addresses))
- .apply_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.subquery()
)
@@ -724,7 +753,7 @@ class ColumnAccessTest(QueryTest, AssertsCompiledSQL):
q1 = select(c1, c2).where(c1 == "dog")
q2 = select(c1, c2).where(c1 == "cat")
subq = q1.union(q2).subquery()
- q3 = select(subq).apply_labels()
+ q3 = select(subq).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
self.assert_compile(
q3.order_by(subq.c.c1),
@@ -738,20 +767,31 @@ class ColumnAccessTest(QueryTest, AssertsCompiledSQL):
from sqlalchemy.sql import column
t1 = table("t1", column("c1"), column("c2"))
- stmt = select(t1.c.c1, t1.c.c2).where(t1.c.c1 == "dog").apply_labels()
+ stmt = (
+ select(t1.c.c1, t1.c.c2)
+ .where(t1.c.c1 == "dog")
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
+ )
- subq1 = stmt.subquery("anon_2").select().apply_labels()
+ subq1 = (
+ stmt.subquery("anon_2")
+ .select()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
+ )
subq2 = subq1.subquery("anon_1")
- q1 = select(subq2).apply_labels()
+ q1 = select(subq2).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
self.assert_compile(
# as in test_anonymous_expression_from_self_twice_newstyle_wlabels,
- # apply_labels() means the subquery cols have long names. however,
- # here we illustrate if they did use apply_labels(), but they also
+ # set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL) means the
+ # subquery cols have long names. however,
+ # here we illustrate if they did use
+ # set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL), but they also
# named the subqueries explicitly as one would certainly do if they
- # were using apply_labels(), we can get at that column based on how
+ # were using set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL),
+ # we can get at that column based on how
# it is aliased, no different than plain SQL.
q1.order_by(subq2.c.anon_2_t1_c1),
"SELECT anon_1.anon_2_t1_c1 "
@@ -769,9 +809,13 @@ class ColumnAccessTest(QueryTest, AssertsCompiledSQL):
c1, c2 = column("c1"), column("c2")
subq = select(c1, c2).where(c1 == "dog").subquery()
- subq2 = select(subq).apply_labels().subquery()
+ subq2 = (
+ select(subq)
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
+ .subquery()
+ )
- stmt = select(subq2).apply_labels()
+ stmt = select(subq2).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
self.assert_compile(
# because of the apply labels we don't have simple keys on
@@ -824,7 +868,7 @@ class ColumnAccessTest(QueryTest, AssertsCompiledSQL):
q1 = select(c1.label("foo"), c2.label("bar")).where(c1 == "dog")
q2 = select(c1.label("foo"), c2.label("bar")).where(c1 == "cat")
subq = union(q1, q2).subquery()
- q3 = select(subq).apply_labels()
+ q3 = select(subq).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
self.assert_compile(
q3.order_by(subq.c.foo),
"SELECT anon_1.foo AS anon_1_foo, anon_1.bar AS anon_1_bar FROM "
@@ -842,7 +886,9 @@ class ColumnAccessTest(QueryTest, AssertsCompiledSQL):
sess = fixture_session()
q1 = sess.query(User.id).filter(User.id > 5)
- uq = aliased(User, q1.apply_labels().subquery())
+ uq = aliased(
+ User, q1.set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL).subquery()
+ )
aa = aliased(Address)
q1 = (
@@ -869,7 +915,12 @@ class ColumnAccessTest(QueryTest, AssertsCompiledSQL):
addresses = self.tables.addresses
sess = fixture_session()
- q1 = sess.query(User.id).filter(User.id > 5).apply_labels().subquery()
+ q1 = (
+ sess.query(User.id)
+ .filter(User.id > 5)
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
+ .subquery()
+ )
uq = aliased(User, q1)
@@ -1029,9 +1080,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
.union(users.select(users.c.id > 7))
.alias("ulist")
.outerjoin(addresses)
- .select(
- use_labels=True, order_by=[text("ulist.id"), addresses.c.id]
- )
+ .select(order_by=[text("ulist.id"), addresses.c.id])
)
sess = fixture_session()
q = sess.query(User)
@@ -1058,9 +1107,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
.union(users.select(users.c.id > 7))
.alias("ulist")
.outerjoin(addresses)
- .select(
- use_labels=True, order_by=[text("ulist.id"), addresses.c.id]
- )
+ .select(order_by=[text("ulist.id"), addresses.c.id])
)
sess = fixture_session()
q = sess.query(User)
@@ -1088,9 +1135,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
.union(users.select(users.c.id > 7))
.alias("ulist")
.outerjoin(addresses)
- .select(
- use_labels=True, order_by=[text("ulist.id"), addresses.c.id]
- )
+ .select(order_by=[text("ulist.id"), addresses.c.id])
)
sess = fixture_session()
@@ -1124,7 +1169,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
.union(users.select(users.c.id > 7))
.alias("ulist")
.outerjoin(adalias)
- .select(use_labels=True, order_by=[text("ulist.id"), adalias.c.id])
+ .select(order_by=[text("ulist.id"), adalias.c.id])
)
def go():
@@ -1151,7 +1196,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
.order_by(User.id, addresses.c.id)
)
self.assert_compile(
- q.with_labels().statement,
+ q.set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL).statement,
"SELECT addresses.id AS addresses_id, "
"addresses.user_id AS addresses_user_id, "
"addresses.email_address AS "
@@ -1201,7 +1246,6 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
selectquery = users.outerjoin(addresses).select(
users.c.id < 10,
- use_labels=True,
order_by=[users.c.id, addresses.c.id],
)
@@ -1228,7 +1272,6 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
selectquery = users.outerjoin(addresses).select(
users.c.id < 10,
- use_labels=True,
order_by=[users.c.id, addresses.c.id],
)
@@ -1286,7 +1329,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL):
users.outerjoin(oalias)
.outerjoin(order_items)
.outerjoin(ialias)
- .select(use_labels=True)
+ .select()
.order_by(users.c.id, oalias.c.id, ialias.c.id)
)
@@ -2135,9 +2178,12 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL):
Order.id, Order.description, literal_column("'q'").label("foo")
).where(Order.description == "order 3")
- subq = aliased(Order, stmt.apply_labels().subquery())
+ subq = aliased(
+ Order,
+ stmt.set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL).subquery(),
+ )
- stmt = select(subq).apply_labels()
+ stmt = select(subq).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
self.assert_compile(
stmt,
"SELECT anon_1.orders_id AS "
@@ -2182,7 +2228,7 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL):
sess = fixture_session(future=True)
selectquery = users.outerjoin(addresses).select(
- use_labels=True, order_by=[users.c.id, addresses.c.id]
+ order_by=[users.c.id, addresses.c.id]
)
result = sess.execute(
diff --git a/test/orm/test_joins.py b/test/orm/test_joins.py
index 79d3db8f0..de5a5c92d 100644
--- a/test/orm/test_joins.py
+++ b/test/orm/test_joins.py
@@ -24,6 +24,7 @@ from sqlalchemy.orm import outerjoin
from sqlalchemy.orm import relationship
from sqlalchemy.orm import Session
from sqlalchemy.orm import synonym
+from sqlalchemy.sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL
from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import AssertsCompiledSQL
@@ -386,7 +387,7 @@ class JoinTest(QueryTest, AssertsCompiledSQL):
subq = (
sess.query(User)
.filter(User.name == "ed")
- .apply_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.subquery()
)
@@ -2199,7 +2200,7 @@ class SelfReferentialTest(fixtures.MappedTest, AssertsCompiledSQL):
subq = (
sess.query(Node)
.filter(Node.data == "n122")
- .apply_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.subquery()
)
@@ -2226,7 +2227,7 @@ class SelfReferentialTest(fixtures.MappedTest, AssertsCompiledSQL):
.filter(Node.data == "n122")
.filter(parent.data == "n12")
.filter(grandparent.data == "n1")
- .apply_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.subquery()
)
na = aliased(Node, subq)
diff --git a/test/orm/test_lambdas.py b/test/orm/test_lambdas.py
index 7591f844f..a1657d746 100644
--- a/test/orm/test_lambdas.py
+++ b/test/orm/test_lambdas.py
@@ -14,6 +14,7 @@ from sqlalchemy.orm import relationship
from sqlalchemy.orm import selectinload
from sqlalchemy.orm import Session
from sqlalchemy.orm import subqueryload
+from sqlalchemy.sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import AssertsCompiledSQL
from sqlalchemy.testing import eq_
@@ -341,19 +342,19 @@ class LambdaTest(QueryTest, AssertsCompiledSQL):
),
lambda User, Address: select(lambda: User)
.join(lambda: Address)
- .apply_labels(),
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL),
lambda User, Address: select(lambda: User)
.join(lambda: User.addresses)
- .apply_labels(),
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL),
lambda User, Address: select(lambda: User)
.join(lambda: Address, lambda: User.addresses)
- .apply_labels(),
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL),
lambda User, Address: select(lambda: User)
.join(Address, lambda: User.addresses)
- .apply_labels(),
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL),
lambda User, Address: select(lambda: User)
.join(lambda: Address, User.addresses)
- .apply_labels(),
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL),
argnames="test_case",
)
def test_join_entity_arg(self, plain_fixture, test_case):
diff --git a/test/orm/test_lazy_relations.py b/test/orm/test_lazy_relations.py
index 921a1b15d..653bf22db 100644
--- a/test/orm/test_lazy_relations.py
+++ b/test/orm/test_lazy_relations.py
@@ -336,13 +336,11 @@ class LazyTest(_fixtures.FixtureTest):
# use a union all to get a lot of rows to join against
u2 = users.alias("u2")
s = sa.union_all(
- u2.select(use_labels=True),
- u2.select(use_labels=True),
- u2.select(use_labels=True),
+ u2.select(),
+ u2.select(),
+ u2.select(),
).alias("u")
- result = (
- q.filter(s.c.u2_id == User.id).order_by(User.id).distinct().all()
- )
+ result = q.filter(s.c.id == User.id).order_by(User.id).distinct().all()
eq_(self.static.user_all_result, result)
def test_uselist_false_warning(self):
diff --git a/test/orm/test_query.py b/test/orm/test_query.py
index 7546ba162..0fb5e7dd6 100644
--- a/test/orm/test_query.py
+++ b/test/orm/test_query.py
@@ -1723,7 +1723,8 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL):
a1 = (
session.query(User.id)
.filter(User.id == 7)
- .subquery(with_labels=True)
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
+ .subquery()
)
assert a1.c.users_id is not None
@@ -1804,8 +1805,8 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL):
s = fixture_session()
- q1 = s.query(User).filter(User.name == "ed").with_labels()
- q2 = s.query(User).filter(User.name == "fred").with_labels()
+ q1 = s.query(User).filter(User.name == "ed")
+ q2 = s.query(User).filter(User.name == "fred")
eq_(
s.query(User)
.from_statement(union(q1, q2).order_by("users_name"))
@@ -1818,15 +1819,12 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL):
s = fixture_session()
- # this is actually not legal on most DBs since the subquery has no
- # alias
q1 = s.query(User).filter(User.name == "ed")
self.assert_compile(
- select(q1.with_labels().subquery()),
- "SELECT anon_1.users_id, anon_1.users_name FROM "
- "(SELECT users.id AS users_id, "
- "users.name AS users_name "
+ select(q1.subquery()),
+ "SELECT anon_1.id, anon_1.name FROM "
+ "(SELECT users.id AS id, users.name AS name "
"FROM users WHERE users.name = :name_1) AS anon_1",
)
@@ -1857,11 +1855,9 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL):
q1 = s.query(User.id, User.name).group_by(User.name)
self.assert_compile(
- select(q1.with_labels().subquery()),
- "SELECT anon_1.users_id, anon_1.users_name FROM "
- "(SELECT users.id AS users_id, "
- "users.name AS users_name FROM users GROUP BY users.name) "
- "AS anon_1",
+ select(q1.subquery()),
+ "SELECT anon_1.id, anon_1.name FROM (SELECT users.id AS id, "
+ "users.name AS name FROM users GROUP BY users.name) AS anon_1",
)
def test_group_by_append(self):
@@ -1872,11 +1868,10 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL):
# test append something to group_by
self.assert_compile(
- select(q1.group_by(User.id).with_labels().subquery()),
- "SELECT anon_1.users_id, anon_1.users_name FROM "
- "(SELECT users.id AS users_id, "
- "users.name AS users_name FROM users "
- "GROUP BY users.name, users.id) AS anon_1",
+ select(q1.group_by(User.id).subquery()),
+ "SELECT anon_1.id, anon_1.name FROM "
+ "(SELECT users.id AS id, users.name AS name "
+ "FROM users GROUP BY users.name, users.id) AS anon_1",
)
def test_group_by_cancellation(self):
@@ -1886,20 +1881,17 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL):
q1 = s.query(User.id, User.name).group_by(User.name)
# test cancellation by using None, replacement with something else
self.assert_compile(
- select(
- q1.group_by(None).group_by(User.id).with_labels().subquery()
- ),
- "SELECT anon_1.users_id, anon_1.users_name FROM "
- "(SELECT users.id AS users_id, "
- "users.name AS users_name FROM users GROUP BY users.id) AS anon_1",
+ select(q1.group_by(None).group_by(User.id).subquery()),
+ "SELECT anon_1.id, anon_1.name FROM "
+ "(SELECT users.id AS id, users.name AS name "
+ "FROM users GROUP BY users.id) AS anon_1",
)
# test cancellation by using None, replacement with nothing
self.assert_compile(
- select(q1.group_by(None).with_labels().subquery()),
- "SELECT anon_1.users_id, anon_1.users_name FROM "
- "(SELECT users.id AS users_id, "
- "users.name AS users_name FROM users) AS anon_1",
+ select(q1.group_by(None).subquery()),
+ "SELECT anon_1.id, anon_1.name FROM (SELECT users.id AS id, "
+ "users.name AS name FROM users) AS anon_1",
)
def test_group_by_cancelled_still_present(self):
@@ -1916,11 +1908,10 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL):
q1 = s.query(User.id, User.name).order_by(User.name)
self.assert_compile(
- select(q1.with_labels().subquery()),
- "SELECT anon_1.users_id, anon_1.users_name FROM "
- "(SELECT users.id AS users_id, "
- "users.name AS users_name FROM users ORDER BY users.name) "
- "AS anon_1",
+ select(q1.subquery()),
+ "SELECT anon_1.id, anon_1.name FROM "
+ "(SELECT users.id AS id, users.name AS name "
+ "FROM users ORDER BY users.name) AS anon_1",
)
def test_order_by_append(self):
@@ -1931,11 +1922,10 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL):
# test append something to order_by
self.assert_compile(
- select(q1.order_by(User.id).with_labels().subquery()),
- "SELECT anon_1.users_id, anon_1.users_name FROM "
- "(SELECT users.id AS users_id, "
- "users.name AS users_name FROM users "
- "ORDER BY users.name, users.id) AS anon_1",
+ select(q1.order_by(User.id).subquery()),
+ "SELECT anon_1.id, anon_1.name FROM "
+ "(SELECT users.id AS id, users.name AS name "
+ "FROM users ORDER BY users.name, users.id) AS anon_1",
)
def test_order_by_cancellation(self):
@@ -1945,20 +1935,16 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL):
q1 = s.query(User.id, User.name).order_by(User.name)
# test cancellation by using None, replacement with something else
self.assert_compile(
- select(
- q1.order_by(None).order_by(User.id).with_labels().subquery()
- ),
- "SELECT anon_1.users_id, anon_1.users_name FROM "
- "(SELECT users.id AS users_id, "
- "users.name AS users_name FROM users ORDER BY users.id) AS anon_1",
+ select(q1.order_by(None).order_by(User.id).subquery()),
+ "SELECT anon_1.id, anon_1.name FROM (SELECT users.id AS id, "
+ "users.name AS name FROM users ORDER BY users.id) AS anon_1",
)
# test cancellation by using None, replacement with nothing
self.assert_compile(
- select(q1.order_by(None).with_labels().subquery()),
- "SELECT anon_1.users_id, anon_1.users_name FROM "
- "(SELECT users.id AS users_id, "
- "users.name AS users_name FROM users) AS anon_1",
+ select(q1.order_by(None).subquery()),
+ "SELECT anon_1.id, anon_1.name FROM (SELECT users.id AS id, "
+ "users.name AS name FROM users) AS anon_1",
)
def test_order_by_cancellation_false(self):
@@ -1968,20 +1954,16 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL):
q1 = s.query(User.id, User.name).order_by(User.name)
# test cancellation by using None, replacement with something else
self.assert_compile(
- select(
- q1.order_by(False).order_by(User.id).with_labels().subquery()
- ),
- "SELECT anon_1.users_id, anon_1.users_name FROM "
- "(SELECT users.id AS users_id, "
- "users.name AS users_name FROM users ORDER BY users.id) AS anon_1",
+ select(q1.order_by(False).order_by(User.id).subquery()),
+ "SELECT anon_1.id, anon_1.name FROM (SELECT users.id AS id, "
+ "users.name AS name FROM users ORDER BY users.id) AS anon_1",
)
# test cancellation by using None, replacement with nothing
self.assert_compile(
- select(q1.order_by(False).with_labels().subquery()),
- "SELECT anon_1.users_id, anon_1.users_name FROM "
- "(SELECT users.id AS users_id, "
- "users.name AS users_name FROM users) AS anon_1",
+ select(q1.order_by(False).subquery()),
+ "SELECT anon_1.id, anon_1.name FROM (SELECT users.id AS id, "
+ "users.name AS name FROM users) AS anon_1",
)
def test_order_by_cancelled_allows_assertions(self):
@@ -2114,7 +2096,9 @@ class ColumnPropertyTest(_fixtures.FixtureTest, AssertsCompiledSQL):
assert_raises_message(
sa.exc.CompileError,
"Can't resolve label reference for ORDER BY / GROUP BY",
- q.with_labels().statement.compile,
+ q.set_label_style(
+ LABEL_STYLE_TABLENAME_PLUS_COL
+ ).statement.compile,
)
def test_order_by_column_labeled_prop_attr_aliased_one(self):
@@ -4032,7 +4016,7 @@ class DistinctTest(QueryTest, AssertsCompiledSQL):
)
.distinct()
.order_by(User.id, User.name, Address.email_address)
- .apply_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.subquery()
)
@@ -4192,7 +4176,7 @@ class DistinctTest(QueryTest, AssertsCompiledSQL):
)
.distinct(Address.email_address)
.order_by(User.id, User.name, Address.email_address)
- .apply_labels()
+ .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
.subquery()
)
@@ -4252,7 +4236,9 @@ class DistinctTest(QueryTest, AssertsCompiledSQL):
sa_exc.CompileError,
"Can't resolve label reference for ORDER BY / "
"GROUP BY / DISTINCT etc.",
- q.with_labels().statement.compile,
+ q.set_label_style(
+ LABEL_STYLE_TABLENAME_PLUS_COL
+ ).statement.compile,
dialect=postgresql.dialect(),
)
@@ -5099,7 +5085,9 @@ class TextTest(QueryTest, AssertsCompiledSQL):
assert_raises_message(
sa_exc.CompileError,
"Can't resolve label reference for ORDER BY / GROUP BY.",
- q.with_labels().statement.compile,
+ q.set_label_style(
+ LABEL_STYLE_TABLENAME_PLUS_COL
+ ).statement.compile,
)
def test_order_by_w_eager_two(self):
@@ -5115,7 +5103,9 @@ class TextTest(QueryTest, AssertsCompiledSQL):
assert_raises_message(
sa_exc.CompileError,
"Can't resolve label reference for ORDER BY / GROUP BY.",
- q.with_labels().statement.compile,
+ q.set_label_style(
+ LABEL_STYLE_TABLENAME_PLUS_COL
+ ).statement.compile,
)
def test_order_by_w_eager_three(self):