summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ext/declarative/test_inheritance.py5
-rw-r--r--test/ext/test_hybrid.py24
-rw-r--r--test/ext/test_serializer.py9
-rw-r--r--test/orm/declarative/test_basic.py133
-rw-r--r--test/orm/declarative/test_mixin.py4
-rw-r--r--test/orm/declarative/test_typed_mapping.py4
-rw-r--r--test/orm/dml/test_update_delete_where.py20
-rw-r--r--test/orm/inheritance/test_basic.py60
-rw-r--r--test/orm/inheritance/test_relationship.py8
-rw-r--r--test/orm/test_core_compilation.py55
-rw-r--r--test/orm/test_deferred.py76
-rw-r--r--test/orm/test_mapper.py4
-rw-r--r--test/orm/test_query.py39
13 files changed, 315 insertions, 126 deletions
diff --git a/test/ext/declarative/test_inheritance.py b/test/ext/declarative/test_inheritance.py
index d22090086..9efe08029 100644
--- a/test/ext/declarative/test_inheritance.py
+++ b/test/ext/declarative/test_inheritance.py
@@ -975,8 +975,9 @@ class ConcreteExtensionConfigTest(
session = Session()
self.assert_compile(
session.query(Document),
- "SELECT pjoin.documenttype AS pjoin_documenttype, "
- "pjoin.id AS pjoin_id, pjoin.type AS pjoin_type FROM "
+ "SELECT "
+ "pjoin.id AS pjoin_id, pjoin.documenttype AS pjoin_documenttype, "
+ "pjoin.type AS pjoin_type FROM "
"(SELECT offers.id AS id, offers.documenttype AS documenttype, "
"'offer' AS type FROM offers) AS pjoin",
)
diff --git a/test/ext/test_hybrid.py b/test/ext/test_hybrid.py
index 0cba8f3a1..252844a48 100644
--- a/test/ext/test_hybrid.py
+++ b/test/ext/test_hybrid.py
@@ -98,7 +98,7 @@ class PropertyComparatorTest(fixtures.TestBase, AssertsCompiledSQL):
sess = fixture_session()
self.assert_compile(
sess.query(aliased(A)).filter_by(value="foo"),
- "SELECT a_1.value AS a_1_value, a_1.id AS a_1_id "
+ "SELECT a_1.id AS a_1_id, a_1.value AS a_1_value "
"FROM a AS a_1 WHERE upper(a_1.value) = upper(:upper_1)",
)
@@ -467,7 +467,7 @@ class PropertyExpressionTest(fixtures.TestBase, AssertsCompiledSQL):
sess = fixture_session()
self.assert_compile(
sess.query(A).filter_by(value="foo"),
- "SELECT a.value AS a_value, a.id AS a_id "
+ "SELECT a.id AS a_id, a.value AS a_value "
"FROM a WHERE foo(a.value) + bar(a.value) = :param_1",
)
@@ -476,7 +476,7 @@ class PropertyExpressionTest(fixtures.TestBase, AssertsCompiledSQL):
sess = fixture_session()
self.assert_compile(
sess.query(aliased(A)).filter_by(value="foo"),
- "SELECT a_1.value AS a_1_value, a_1.id AS a_1_id "
+ "SELECT a_1.id AS a_1_id, a_1.value AS a_1_value "
"FROM a AS a_1 WHERE foo(a_1.value) + bar(a_1.value) = :param_1",
)
@@ -914,7 +914,7 @@ class MethodExpressionTest(fixtures.TestBase, AssertsCompiledSQL):
sess = fixture_session()
self.assert_compile(
sess.query(A).filter(A.value(5) == "foo"),
- "SELECT a.value AS a_value, a.id AS a_id "
+ "SELECT a.id AS a_id, a.value AS a_value "
"FROM a WHERE foo(a.value, :foo_1) + :foo_2 = :param_1",
)
@@ -924,7 +924,7 @@ class MethodExpressionTest(fixtures.TestBase, AssertsCompiledSQL):
a1 = aliased(A)
self.assert_compile(
sess.query(a1).filter(a1.value(5) == "foo"),
- "SELECT a_1.value AS a_1_value, a_1.id AS a_1_id "
+ "SELECT a_1.id AS a_1_id, a_1.value AS a_1_value "
"FROM a AS a_1 WHERE foo(a_1.value, :foo_1) + :foo_2 = :param_1",
)
@@ -1381,8 +1381,9 @@ class SpecialObjectTest(fixtures.TestBase, AssertsCompiledSQL):
self.assert_compile(
query,
- "SELECT bank_account.balance AS bank_account_balance, "
- "bank_account.id AS bank_account_id FROM bank_account "
+ "SELECT bank_account.id AS bank_account_id, "
+ "bank_account.balance AS bank_account_balance "
+ "FROM bank_account "
"WHERE bank_account.balance = :balance_1",
checkparams={"balance_1": Decimal("9886.110000")},
)
@@ -1403,8 +1404,8 @@ class SpecialObjectTest(fixtures.TestBase, AssertsCompiledSQL):
)
self.assert_compile(
query,
- "SELECT bank_account.balance AS bank_account_balance, "
- "bank_account.id AS bank_account_id "
+ "SELECT bank_account.id AS bank_account_id, "
+ "bank_account.balance AS bank_account_balance "
"FROM bank_account "
"WHERE :balance_1 * bank_account.balance > :param_1 "
"AND :balance_2 * bank_account.balance < :param_2",
@@ -1426,8 +1427,9 @@ class SpecialObjectTest(fixtures.TestBase, AssertsCompiledSQL):
)
self.assert_compile(
query,
- "SELECT bank_account.balance AS bank_account_balance, "
- "bank_account.id AS bank_account_id FROM bank_account "
+ "SELECT bank_account.id AS bank_account_id, "
+ "bank_account.balance AS bank_account_balance "
+ "FROM bank_account "
"WHERE :balance_1 * bank_account.balance > "
":param_1 * :balance_2 * bank_account.balance",
checkparams={
diff --git a/test/ext/test_serializer.py b/test/ext/test_serializer.py
index 76fd90fa8..e15ace2eb 100644
--- a/test/ext/test_serializer.py
+++ b/test/ext/test_serializer.py
@@ -316,9 +316,9 @@ class ColumnPropertyWParamTest(
# note in the original, the same bound parameter is used twice
self.assert_compile(
expr,
- "SELECT test.some_id AS test_some_id, "
+ "SELECT "
"CAST(left(test.some_id, :left_1) AS INTEGER) AS anon_1, "
- "test.id AS test_id FROM test WHERE "
+ "test.id AS test_id, test.some_id AS test_some_id FROM test WHERE "
"CAST(left(test.some_id, :left_1) AS INTEGER) = :param_1",
checkparams={"left_1": 6, "param_1": 123456},
)
@@ -328,9 +328,8 @@ class ColumnPropertyWParamTest(
# the same value however
self.assert_compile(
expr2,
- "SELECT test.some_id AS test_some_id, "
- "CAST(left(test.some_id, :left_1) AS INTEGER) AS anon_1, "
- "test.id AS test_id FROM test WHERE "
+ "SELECT CAST(left(test.some_id, :left_1) AS INTEGER) AS anon_1, "
+ "test.id AS test_id, test.some_id AS test_some_id FROM test WHERE "
"CAST(left(test.some_id, :left_2) AS INTEGER) = :param_1",
checkparams={"left_1": 6, "left_2": 6, "param_1": 123456},
)
diff --git a/test/orm/declarative/test_basic.py b/test/orm/declarative/test_basic.py
index 9f8e81d91..6959d06ac 100644
--- a/test/orm/declarative/test_basic.py
+++ b/test/orm/declarative/test_basic.py
@@ -1,3 +1,5 @@
+import random
+
import sqlalchemy as sa
from sqlalchemy import CheckConstraint
from sqlalchemy import event
@@ -7,6 +9,7 @@ from sqlalchemy import ForeignKeyConstraint
from sqlalchemy import Index
from sqlalchemy import inspect
from sqlalchemy import Integer
+from sqlalchemy import select
from sqlalchemy import String
from sqlalchemy import testing
from sqlalchemy import UniqueConstraint
@@ -27,6 +30,7 @@ from sqlalchemy.orm import descriptor_props
from sqlalchemy.orm import exc as orm_exc
from sqlalchemy.orm import joinedload
from sqlalchemy.orm import mapped_column
+from sqlalchemy.orm import MappedColumn
from sqlalchemy.orm import Mapper
from sqlalchemy.orm import registry
from sqlalchemy.orm import relationship
@@ -2588,3 +2592,132 @@ class DeclarativeMultiBaseTest(
mt = MyTable(id=5)
eq_(mt.id, 5)
+
+
+class NamedAttrOrderingTest(fixtures.TestBase):
+ """test for #8705"""
+
+ @testing.combinations(
+ "decl_base_fn",
+ "decl_base_base",
+ "classical_mapping",
+ argnames="mapping_style",
+ )
+ def test_ordering_of_attrs_cols_named_or_unnamed(self, mapping_style):
+ def make_name():
+ uppercase = random.randint(1, 3) == 1
+ name = "".join(
+ random.choice("abcdefghijklmnopqrstuvxyz")
+ for i in range(random.randint(4, 10))
+ )
+ if uppercase:
+ name = random.choice("ABCDEFGHIJKLMNOP") + name
+ return name
+
+ def make_column(assign_col_name):
+ use_key = random.randint(1, 3) == 1
+ use_name = random.randint(1, 3) == 1
+
+ args = []
+ kw = {}
+ name = col_name = make_name()
+
+ if use_name:
+ use_different_name = random.randint(1, 3) != 3
+ if use_different_name:
+ col_name = make_name()
+
+ args.append(col_name)
+ elif assign_col_name:
+ args.append(col_name)
+
+ if use_key:
+ kw["key"] = name
+ expected_c_name = name
+ else:
+ expected_c_name = col_name
+
+ args.append(Integer)
+
+ if mapping_style.startswith("decl"):
+ use_mapped_column = random.randint(1, 2) == 1
+ else:
+ use_mapped_column = False
+
+ if use_mapped_column:
+ col = mapped_column(*args, **kw)
+ else:
+ col = Column(*args, **kw)
+
+ use_explicit_property = (
+ not use_mapped_column and random.randint(1, 6) == 1
+ )
+ if use_explicit_property:
+ col_prop = column_property(col)
+ else:
+ col_prop = col
+
+ return name, expected_c_name, col, col_prop
+
+ assign_col_name = mapping_style == "classical_mapping"
+
+ names = [
+ make_column(assign_col_name) for i in range(random.randint(10, 15))
+ ]
+ len_names = len(names)
+
+ pk_col = names[random.randint(0, len_names - 1)][2]
+ if isinstance(pk_col, MappedColumn):
+ pk_col.column.primary_key = True
+ else:
+ pk_col.primary_key = True
+
+ names_only = [name for name, _, _, _ in names]
+ col_names_only = [col_name for _, col_name, _, _ in names]
+ cols_only = [col for _, _, col, _ in names]
+
+ if mapping_style in ("decl_base_fn", "decl_base_base"):
+ if mapping_style == "decl_base_fn":
+ Base = declarative_base()
+ elif mapping_style == "decl_base_base":
+
+ class Base(DeclarativeBase):
+ pass
+
+ else:
+ assert False
+
+ clsdict = {
+ "__tablename__": "new_table",
+ }
+ clsdict.update({name: colprop for name, _, _, colprop in names})
+
+ new_cls = type("NewCls", (Base,), clsdict)
+
+ elif mapping_style == "classical_mapping":
+
+ class new_cls:
+ pass
+
+ reg = registry()
+ t = Table("new_table", reg.metadata, *cols_only)
+
+ reg.map_imperatively(
+ new_cls,
+ t,
+ properties={
+ key: colprop
+ for key, col_name, col, colprop in names
+ if col_name != key
+ },
+ )
+ else:
+ assert False
+
+ eq_(new_cls.__table__.c.keys(), col_names_only)
+ eq_(new_cls.__mapper__.attrs.keys(), names_only)
+ eq_(list(new_cls._sa_class_manager.keys()), names_only)
+ eq_([k for k in new_cls.__dict__ if not k.startswith("_")], names_only)
+
+ stmt = select(new_cls)
+ eq_(stmt.selected_columns.keys(), col_names_only)
diff --git a/test/orm/declarative/test_mixin.py b/test/orm/declarative/test_mixin.py
index 4d438e68b..967958846 100644
--- a/test/orm/declarative/test_mixin.py
+++ b/test/orm/declarative/test_mixin.py
@@ -2017,11 +2017,11 @@ class DeclaredAttrTest(DeclarativeTestBase, testing.AssertsCompiledSQL):
s = fixture_session()
self.assert_compile(
s.query(A),
- "SELECT a.x + :x_1 AS anon_1, a.x AS a_x, a.id AS a_id FROM a",
+ "SELECT a.x + :x_1 AS anon_1, a.id AS a_id, a.x AS a_x FROM a",
)
self.assert_compile(
s.query(B),
- "SELECT b.x + :x_1 AS anon_1, b.x AS b_x, b.id AS b_id FROM b",
+ "SELECT b.x + :x_1 AS anon_1, b.id AS b_id, b.x AS b_x FROM b",
)
@testing.requires.predictable_gc
diff --git a/test/orm/declarative/test_typed_mapping.py b/test/orm/declarative/test_typed_mapping.py
index 1b4be84d3..72fd4d84e 100644
--- a/test/orm/declarative/test_typed_mapping.py
+++ b/test/orm/declarative/test_typed_mapping.py
@@ -1004,7 +1004,7 @@ class MappedColumnTest(fixtures.TestBase, testing.AssertsCompiledSQL):
self.assert_compile(select(User), "SELECT users.id FROM users")
self.assert_compile(
select(User).options(undefer(User.data)),
- "SELECT users.data, users.id FROM users",
+ "SELECT users.id, users.data FROM users",
)
def test_deferred_kw(self, decl_base):
@@ -1017,7 +1017,7 @@ class MappedColumnTest(fixtures.TestBase, testing.AssertsCompiledSQL):
self.assert_compile(select(User), "SELECT users.id FROM users")
self.assert_compile(
select(User).options(undefer(User.data)),
- "SELECT users.data, users.id FROM users",
+ "SELECT users.id, users.data FROM users",
)
@testing.combinations(
diff --git a/test/orm/dml/test_update_delete_where.py b/test/orm/dml/test_update_delete_where.py
index ebaba191a..9c8809eef 100644
--- a/test/orm/dml/test_update_delete_where.py
+++ b/test/orm/dml/test_update_delete_where.py
@@ -533,15 +533,15 @@ class UpdateDeleteTest(fixtures.MappedTest):
to_assert = [
# refresh john
CompiledSQL(
- "SELECT users.age_int AS users_age_int, "
- "users.id AS users_id, users.name AS users_name FROM users "
+ "SELECT users.id AS users_id, users.name AS users_name, "
+ "users.age_int AS users_age_int FROM users "
"WHERE users.id = :pk_1",
[{"pk_1": 1}],
),
# refresh jill
CompiledSQL(
- "SELECT users.age_int AS users_age_int, "
- "users.id AS users_id, users.name AS users_name FROM users "
+ "SELECT users.id AS users_id, users.name AS users_name, "
+ "users.age_int AS users_age_int FROM users "
"WHERE users.id = :pk_1",
[{"pk_1": 3}],
),
@@ -551,8 +551,8 @@ class UpdateDeleteTest(fixtures.MappedTest):
to_assert.append(
# refresh jane for partial attributes
CompiledSQL(
- "SELECT users.age_int AS users_age_int, "
- "users.name AS users_name FROM users "
+ "SELECT users.name AS users_name, "
+ "users.age_int AS users_age_int FROM users "
"WHERE users.id = :pk_1",
[{"pk_1": 4}],
)
@@ -677,15 +677,15 @@ class UpdateDeleteTest(fixtures.MappedTest):
asserter.assert_(
# refresh john
CompiledSQL(
- "SELECT users.age_int AS users_age_int, "
- "users.id AS users_id, users.name AS users_name FROM users "
+ "SELECT users.id AS users_id, users.name AS users_name, "
+ "users.age_int AS users_age_int FROM users "
"WHERE users.id = :pk_1",
[{"pk_1": 1}],
),
# refresh jill
CompiledSQL(
- "SELECT users.age_int AS users_age_int, "
- "users.id AS users_id, users.name AS users_name FROM users "
+ "SELECT users.id AS users_id, users.name AS users_name, "
+ "users.age_int AS users_age_int FROM users "
"WHERE users.id = :pk_1",
[{"pk_1": 3}],
),
diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py
index 9d7b73e1c..0ba900798 100644
--- a/test/orm/inheritance/test_basic.py
+++ b/test/orm/inheritance/test_basic.py
@@ -32,6 +32,7 @@ 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_
+from sqlalchemy.testing import expect_raises_message
from sqlalchemy.testing import expect_warnings
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import is_
@@ -2518,6 +2519,50 @@ class OverrideColKeyTest(fixtures.MappedTest):
# PK col
assert s2.id == s2.base_id != 15
+ def test_subclass_renames_superclass_col_single_inh(self, decl_base):
+ """tested as part of #8705.
+
+ The step where we configure columns mapped to specific keys must
+ take place even if the given column is already in _columntoproperty,
+ as would be the case if the superclass maps that column already.
+
+ """
+
+ class A(decl_base):
+ __tablename__ = "a"
+
+ id = Column(Integer, primary_key=True)
+ a_data = Column(String)
+
+ class B(A):
+ b_data = column_property(A.__table__.c.a_data)
+
+ is_(A.a_data.property.columns[0], A.__table__.c.a_data)
+ is_(B.a_data.property.columns[0], A.__table__.c.a_data)
+ is_(B.b_data.property.columns[0], A.__table__.c.a_data)
+
+ def test_column_setup_sanity_check(self, decl_base):
+ class A(decl_base):
+ __tablename__ = "a"
+
+ id = Column(Integer, primary_key=True)
+ a_data = Column(String)
+
+ class B(A):
+ __tablename__ = "b"
+ id = Column(Integer, ForeignKey("a.id"), primary_key=True)
+ b_data = Column(String)
+
+ is_(A.id.property.parent, inspect(A))
+ # overlapping cols get a new prop on the subclass, with cols merged
+ is_(B.id.property.parent, inspect(B))
+ eq_(B.id.property.columns, [B.__table__.c.id, A.__table__.c.id])
+
+ # totally independent cols remain w/ parent on the originating
+ # mapper
+ is_(B.a_data.property.parent, inspect(A))
+ is_(B.b_data.property.parent, inspect(B))
+
def test_override_implicit(self):
# this is originally [ticket:1111].
# the pattern here is now disallowed by [ticket:1892]
@@ -2532,7 +2577,12 @@ class OverrideColKeyTest(fixtures.MappedTest):
Base, base, properties={"id": base.c.base_id}
)
- def go():
+ with expect_raises_message(
+ sa_exc.InvalidRequestError,
+ "Implicitly combining column base.base_id with column "
+ "subtable.base_id under attribute 'id'. Please configure one "
+ "or more attributes for these same-named columns explicitly.",
+ ):
self.mapper_registry.map_imperatively(
Sub,
subtable,
@@ -2540,12 +2590,6 @@ class OverrideColKeyTest(fixtures.MappedTest):
properties={"id": subtable.c.base_id},
)
- # Sub mapper compilation needs to detect that "base.c.base_id"
- # is renamed in the inherited mapper as "id", even though
- # it has its own "id" property. It then generates
- # an exception in 0.7 due to the implicit conflict.
- assert_raises(sa_exc.InvalidRequestError, go)
-
def test_pk_fk_different(self):
class Base:
pass
@@ -2745,9 +2789,9 @@ class OptimizedLoadTest(fixtures.MappedTest):
go,
CompiledSQL(
"SELECT base.id AS base_id, sub.id AS sub_id, "
+ "base.data AS base_data, base.type AS base_type, "
"base.counter AS base_counter, "
"sub.subcounter AS sub_subcounter, "
- "base.data AS base_data, base.type AS base_type, "
"sub.sub AS sub_sub, sub.subcounter2 AS sub_subcounter2 "
"FROM base LEFT OUTER JOIN sub ON base.id = sub.id "
"WHERE base.id = :pk_1",
diff --git a/test/orm/inheritance/test_relationship.py b/test/orm/inheritance/test_relationship.py
index 779239015..925bf7dd0 100644
--- a/test/orm/inheritance/test_relationship.py
+++ b/test/orm/inheritance/test_relationship.py
@@ -2901,14 +2901,14 @@ class BetweenSubclassJoinWExtraJoinedLoad(
) if autoalias else nullcontext():
self.assert_compile(
q,
- "SELECT people.type AS people_type, engineers.id AS "
+ "SELECT engineers.id AS "
"engineers_id, "
- "people.id AS people_id, "
+ "people.id AS people_id, people.type AS people_type, "
"engineers.primary_language AS engineers_primary_language, "
"engineers.manager_id AS engineers_manager_id, "
- "people_1.type AS people_1_type, "
"managers_1.id AS managers_1_id, "
- "people_1.id AS people_1_id, seen_1.id AS seen_1_id, "
+ "people_1.id AS people_1_id, people_1.type AS people_1_type, "
+ "seen_1.id AS seen_1_id, "
"seen_1.timestamp AS seen_1_timestamp, "
"seen_2.id AS seen_2_id, "
"seen_2.timestamp AS seen_2_timestamp "
diff --git a/test/orm/test_core_compilation.py b/test/orm/test_core_compilation.py
index efa4c773a..8fd22bdd0 100644
--- a/test/orm/test_core_compilation.py
+++ b/test/orm/test_core_compilation.py
@@ -774,8 +774,8 @@ class LoadersInSubqueriesTest(QueryTest, AssertsCompiledSQL):
self.assert_compile(
q,
"SELECT anon_1.id "
- "FROM (SELECT users.name AS name, "
- "users.id AS id FROM users) AS anon_1",
+ "FROM (SELECT users.id AS id, users.name AS name "
+ "FROM users) AS anon_1",
)
# testing deferred opts separately for deterministic SQL generation
@@ -784,9 +784,9 @@ class LoadersInSubqueriesTest(QueryTest, AssertsCompiledSQL):
self.assert_compile(
q,
- "SELECT anon_1.name, anon_1.id "
- "FROM (SELECT users.name AS name, "
- "users.id AS id FROM users) AS anon_1",
+ "SELECT anon_1.id, anon_1.name "
+ "FROM (SELECT users.id AS id, users.name AS name "
+ "FROM users) AS anon_1",
)
q = select(u1).options(undefer(u1.name_upper))
@@ -794,8 +794,8 @@ class LoadersInSubqueriesTest(QueryTest, AssertsCompiledSQL):
self.assert_compile(
q,
"SELECT upper(anon_1.name) AS upper_1, anon_1.id "
- "FROM (SELECT users.name AS name, "
- "users.id AS id FROM users) AS anon_1",
+ "FROM (SELECT users.id AS id, users.name AS name "
+ "FROM users) AS anon_1",
)
def test_non_deferred_subq_one(self, non_deferred_fixture):
@@ -876,9 +876,9 @@ class LoadersInSubqueriesTest(QueryTest, AssertsCompiledSQL):
self.assert_compile(
stmt,
- "WITH RECURSIVE anon_1(name, id) AS "
- "(SELECT users.name AS name, users.id AS id FROM users "
- "UNION ALL SELECT users.name AS name, users.id AS id "
+ "WITH RECURSIVE anon_1(id, name) AS "
+ "(SELECT users.id AS id, users.name AS name FROM users "
+ "UNION ALL SELECT users.id AS id, users.name AS name "
"FROM users JOIN anon_1 ON anon_1.id = users.id) "
"SELECT users.id FROM users JOIN anon_1 ON users.id = anon_1.id",
)
@@ -886,9 +886,9 @@ class LoadersInSubqueriesTest(QueryTest, AssertsCompiledSQL):
# testing deferred opts separately for deterministic SQL generation
self.assert_compile(
stmt.options(undefer(User.name_upper)),
- "WITH RECURSIVE anon_1(name, id) AS "
- "(SELECT users.name AS name, users.id AS id FROM users "
- "UNION ALL SELECT users.name AS name, users.id AS id "
+ "WITH RECURSIVE anon_1(id, name) AS "
+ "(SELECT users.id AS id, users.name AS name FROM users "
+ "UNION ALL SELECT users.id AS id, users.name AS name "
"FROM users JOIN anon_1 ON anon_1.id = users.id) "
"SELECT upper(users.name) AS upper_1, users.id "
"FROM users JOIN anon_1 ON users.id = anon_1.id",
@@ -896,11 +896,11 @@ class LoadersInSubqueriesTest(QueryTest, AssertsCompiledSQL):
self.assert_compile(
stmt.options(undefer(User.name)),
- "WITH RECURSIVE anon_1(name, id) AS "
- "(SELECT users.name AS name, users.id AS id FROM users "
- "UNION ALL SELECT users.name AS name, users.id AS id "
+ "WITH RECURSIVE anon_1(id, name) AS "
+ "(SELECT users.id AS id, users.name AS name FROM users "
+ "UNION ALL SELECT users.id AS id, users.name AS name "
"FROM users JOIN anon_1 ON anon_1.id = users.id) "
- "SELECT users.name, users.id "
+ "SELECT users.id, users.name "
"FROM users JOIN anon_1 ON users.id = anon_1.id",
)
@@ -919,12 +919,13 @@ class LoadersInSubqueriesTest(QueryTest, AssertsCompiledSQL):
self.assert_compile(
select(u_alias),
- "SELECT anon_1.id FROM ((SELECT users.name AS name, "
- "users.id AS id FROM users "
- "WHERE users.id = :id_1 UNION SELECT users.name AS name, "
- "users.id AS id "
+ "SELECT anon_1.id FROM ((SELECT users.id AS id, "
+ "users.name AS name "
+ "FROM users "
+ "WHERE users.id = :id_1 UNION SELECT users.id AS id, "
+ "users.name AS name "
"FROM users WHERE users.id = :id_2) "
- "UNION SELECT users.name AS name, users.id AS id "
+ "UNION SELECT users.id AS id, users.name AS name "
"FROM users WHERE users.id = :id_3) AS anon_1",
)
@@ -949,12 +950,12 @@ class LoadersInSubqueriesTest(QueryTest, AssertsCompiledSQL):
self.assert_compile(
select(u_alias).options(undefer(u_alias.name)),
- "SELECT anon_1.name, anon_1.id FROM "
- "((SELECT users.name AS name, users.id AS id FROM users "
- "WHERE users.id = :id_1 UNION SELECT users.name AS name, "
- "users.id AS id "
+ "SELECT anon_1.id, anon_1.name FROM "
+ "((SELECT users.id AS id, users.name AS name FROM users "
+ "WHERE users.id = :id_1 UNION SELECT users.id AS id, "
+ "users.name AS name "
"FROM users WHERE users.id = :id_2) "
- "UNION SELECT users.name AS name, users.id AS id "
+ "UNION SELECT users.id AS id, users.name AS name "
"FROM users WHERE users.id = :id_3) AS anon_1",
)
diff --git a/test/orm/test_deferred.py b/test/orm/test_deferred.py
index 1c5dadc01..5bd70ca7b 100644
--- a/test/orm/test_deferred.py
+++ b/test/orm/test_deferred.py
@@ -162,8 +162,9 @@ class DeferredTest(AssertsCompiledSQL, _fixtures.FixtureTest):
)
self.assert_compile(
select(Order).options(undefer_group("g1")),
- "SELECT orders.isopen, orders.description, orders.id, "
- "orders.user_id, orders.address_id FROM orders",
+ "SELECT orders.id, orders.user_id, orders.address_id, "
+ "orders.isopen, orders.description "
+ "FROM orders",
)
else:
self.assert_compile(
@@ -583,11 +584,11 @@ class DeferredOptionsTest(AssertsCompiledSQL, _fixtures.FixtureTest):
go,
[
(
- "SELECT orders.user_id AS orders_user_id, "
+ "SELECT orders.id AS orders_id, "
+ "orders.user_id AS orders_user_id, "
+ "orders.address_id AS orders_address_id, "
"orders.description AS orders_description, "
- "orders.isopen AS orders_isopen, "
- "orders.id AS orders_id, "
- "orders.address_id AS orders_address_id "
+ "orders.isopen AS orders_isopen "
"FROM orders ORDER BY orders.id",
{},
)
@@ -628,11 +629,12 @@ class DeferredOptionsTest(AssertsCompiledSQL, _fixtures.FixtureTest):
go,
[
(
- "SELECT orders.user_id AS orders_user_id, "
- "orders.description AS orders_description, "
- "orders.isopen AS orders_isopen, "
+ "SELECT "
"orders.id AS orders_id, "
- "orders.address_id AS orders_address_id "
+ "orders.user_id AS orders_user_id, "
+ "orders.address_id AS orders_address_id, "
+ "orders.description AS orders_description, "
+ "orders.isopen AS orders_isopen "
"FROM orders ORDER BY orders.id",
{},
)
@@ -673,11 +675,12 @@ class DeferredOptionsTest(AssertsCompiledSQL, _fixtures.FixtureTest):
go,
[
(
- "SELECT orders.user_id AS orders_user_id, "
- "orders.description AS orders_description, "
- "orders.isopen AS orders_isopen, "
+ "SELECT "
"orders.id AS orders_id, "
- "orders.address_id AS orders_address_id "
+ "orders.user_id AS orders_user_id, "
+ "orders.address_id AS orders_address_id, "
+ "orders.description AS orders_description, "
+ "orders.isopen AS orders_isopen "
"FROM orders ORDER BY orders.id",
{},
)
@@ -735,11 +738,11 @@ class DeferredOptionsTest(AssertsCompiledSQL, _fixtures.FixtureTest):
{"id_1": 7},
),
(
- "SELECT orders.user_id AS orders_user_id, "
- "orders.description "
- "AS orders_description, orders.isopen AS orders_isopen, "
- "orders.id AS orders_id, orders.address_id "
- "AS orders_address_id "
+ "SELECT orders.id AS orders_id, "
+ "orders.user_id AS orders_user_id, "
+ "orders.address_id AS orders_address_id, "
+ "orders.description AS orders_description, "
+ "orders.isopen AS orders_isopen "
"FROM orders WHERE :param_1 = orders.user_id "
"ORDER BY orders.id",
{"param_1": 7},
@@ -798,11 +801,12 @@ class DeferredOptionsTest(AssertsCompiledSQL, _fixtures.FixtureTest):
{"id_1": 7},
),
(
- "SELECT orders.user_id AS orders_user_id, "
- "orders.description "
- "AS orders_description, orders.isopen AS orders_isopen, "
+ "SELECT "
"orders.id AS orders_id, "
+ "orders.user_id AS orders_user_id, "
"orders.address_id AS orders_address_id, "
+ "orders.description AS orders_description, "
+ "orders.isopen AS orders_isopen, "
"anon_1.users_id AS anon_1_users_id "
"FROM (SELECT users.id AS "
"users_id FROM users WHERE users.id = :id_1) AS anon_1 "
@@ -860,11 +864,12 @@ class DeferredOptionsTest(AssertsCompiledSQL, _fixtures.FixtureTest):
[
(
"SELECT users.id AS users_id, users.name AS users_name, "
+ "orders_1.id AS orders_1_id, "
"orders_1.user_id AS orders_1_user_id, "
+ "orders_1.address_id AS orders_1_address_id, "
"orders_1.description AS orders_1_description, "
- "orders_1.isopen AS orders_1_isopen, "
- "orders_1.id AS orders_1_id, orders_1.address_id AS "
- "orders_1_address_id FROM users "
+ "orders_1.isopen AS orders_1_isopen "
+ "FROM users "
"LEFT OUTER JOIN orders AS orders_1 ON users.id = "
"orders_1.user_id WHERE users.id = :id_1 "
"ORDER BY orders_1.id",
@@ -923,12 +928,13 @@ class DeferredOptionsTest(AssertsCompiledSQL, _fixtures.FixtureTest):
[
(
"SELECT users.id AS users_id, users.name AS users_name, "
- "orders_1.user_id AS orders_1_user_id, "
"lower(orders_1.description) AS lower_1, "
- "orders_1.isopen AS orders_1_isopen, "
"orders_1.id AS orders_1_id, "
+ "orders_1.user_id AS orders_1_user_id, "
"orders_1.address_id AS orders_1_address_id, "
- "orders_1.description AS orders_1_description FROM users "
+ "orders_1.description AS orders_1_description, "
+ "orders_1.isopen AS orders_1_isopen "
+ "FROM users "
"LEFT OUTER JOIN orders AS orders_1 ON users.id = "
"orders_1.user_id WHERE users.id = :id_1 "
"ORDER BY orders_1.id",
@@ -956,11 +962,12 @@ class DeferredOptionsTest(AssertsCompiledSQL, _fixtures.FixtureTest):
q = sess.query(Order).options(Load(Order).undefer("*"))
self.assert_compile(
q,
- "SELECT orders.user_id AS orders_user_id, "
- "orders.description AS orders_description, "
- "orders.isopen AS orders_isopen, "
+ "SELECT "
"orders.id AS orders_id, "
- "orders.address_id AS orders_address_id "
+ "orders.user_id AS orders_user_id, "
+ "orders.address_id AS orders_address_id, "
+ "orders.description AS orders_description, "
+ "orders.isopen AS orders_isopen "
"FROM orders",
)
@@ -1322,9 +1329,8 @@ class DeferredOptionsTest(AssertsCompiledSQL, _fixtures.FixtureTest):
)
self.assert_compile(
q,
- "SELECT orders.description AS orders_description, "
- "orders.id AS orders_id, "
- "orders.user_id AS orders_user_id, "
+ "SELECT orders.id AS orders_id, orders.user_id AS orders_user_id, "
+ "orders.description AS orders_description, "
"orders.isopen AS orders_isopen FROM orders",
)
diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py
index 0aa38ca54..e06908621 100644
--- a/test/orm/test_mapper.py
+++ b/test/orm/test_mapper.py
@@ -910,9 +910,9 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL):
self.assert_compile(
q,
"SELECT "
- "addresses_1.id AS addresses_1_id, "
"users_1.id AS users_1_id, "
"users_1.name AS users_1_name, "
+ "addresses_1.id AS addresses_1_id, "
"addresses_1.user_id AS addresses_1_user_id, "
"addresses_1.email_address AS "
"addresses_1_email_address, "
@@ -928,9 +928,9 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL):
self.assert_compile(
q,
"SELECT "
- "addresses_1.id AS addresses_1_id, "
"users_1.id AS users_1_id, "
"users_1.name AS users_1_name, "
+ "addresses_1.id AS addresses_1_id, "
"addresses_1.user_id AS addresses_1_user_id, "
"addresses_1.email_address AS "
"addresses_1_email_address, "
diff --git a/test/orm/test_query.py b/test/orm/test_query.py
index 559f4ed9d..463009065 100644
--- a/test/orm/test_query.py
+++ b/test/orm/test_query.py
@@ -4221,10 +4221,10 @@ class SetOpsWDeferredTest(QueryTest, AssertsCompiledSQL):
self.assert_compile(
stmt,
"SELECT anon_1.users_id AS anon_1_users_id FROM "
- "(SELECT users.name AS users_name, users.id AS users_id "
+ "(SELECT users.id AS users_id, users.name AS users_name "
"FROM users WHERE users.id = :id_1 "
"UNION "
- "SELECT users.name AS users_name, users.id AS users_id FROM users "
+ "SELECT users.id AS users_id, users.name AS users_name FROM users "
"WHERE users.id = :id_2) AS anon_1 ORDER BY anon_1.users_id",
)
@@ -4253,12 +4253,13 @@ class SetOpsWDeferredTest(QueryTest, AssertsCompiledSQL):
stmt = s1.union(s2).options(undefer(User.name)).order_by(User.id)
self.assert_compile(
stmt,
- "SELECT anon_1.users_name AS anon_1_users_name, "
- "anon_1.users_id AS anon_1_users_id FROM "
- "(SELECT users.name AS users_name, users.id AS users_id "
+ "SELECT anon_1.users_id AS anon_1_users_id, "
+ "anon_1.users_name AS anon_1_users_name "
+ "FROM "
+ "(SELECT users.id AS users_id, users.name AS users_name "
"FROM users WHERE users.id = :id_1 "
"UNION "
- "SELECT users.name AS users_name, users.id AS users_id "
+ "SELECT users.id AS users_id, users.name AS users_name "
"FROM users WHERE users.id = :id_2) AS anon_1 "
"ORDER BY anon_1.users_id",
)
@@ -4298,14 +4299,15 @@ class SetOpsWDeferredTest(QueryTest, AssertsCompiledSQL):
stmt,
"SELECT anon_1.anon_2_users_id AS anon_1_anon_2_users_id "
"FROM ("
- "SELECT anon_2.users_name AS anon_2_users_name, "
- "anon_2.users_id AS anon_2_users_id FROM "
- "(SELECT users.name AS users_name, users.id AS users_id "
+ "SELECT anon_2.users_id AS anon_2_users_id, "
+ "anon_2.users_name AS anon_2_users_name "
+ "FROM "
+ "(SELECT users.id AS users_id, users.name AS users_name "
"FROM users WHERE users.id = :id_1 UNION "
- "SELECT users.name AS users_name, users.id AS users_id "
+ "SELECT users.id AS users_id, users.name AS users_name "
"FROM users WHERE users.id = :id_2) AS anon_2 "
"UNION "
- "SELECT users.name AS users_name, users.id AS users_id FROM users "
+ "SELECT users.id AS users_id, users.name AS users_name FROM users "
"WHERE users.id = :id_3) AS anon_1 "
"ORDER BY anon_1.anon_2_users_id",
)
@@ -4342,17 +4344,18 @@ class SetOpsWDeferredTest(QueryTest, AssertsCompiledSQL):
)
self.assert_compile(
stmt,
- "SELECT anon_1.anon_2_users_name AS anon_1_anon_2_users_name, "
- "anon_1.anon_2_users_id AS anon_1_anon_2_users_id "
+ "SELECT anon_1.anon_2_users_id AS anon_1_anon_2_users_id, "
+ "anon_1.anon_2_users_name AS anon_1_anon_2_users_name "
"FROM ("
- "SELECT anon_2.users_name AS anon_2_users_name, "
- "anon_2.users_id AS anon_2_users_id FROM "
- "(SELECT users.name AS users_name, users.id AS users_id "
+ "SELECT anon_2.users_id AS anon_2_users_id, "
+ "anon_2.users_name AS anon_2_users_name "
+ "FROM "
+ "(SELECT users.id AS users_id, users.name AS users_name "
"FROM users WHERE users.id = :id_1 UNION "
- "SELECT users.name AS users_name, users.id AS users_id "
+ "SELECT users.id AS users_id, users.name AS users_name "
"FROM users WHERE users.id = :id_2) AS anon_2 "
"UNION "
- "SELECT users.name AS users_name, users.id AS users_id FROM users "
+ "SELECT users.id AS users_id, users.name AS users_name FROM users "
"WHERE users.id = :id_3) AS anon_1 "
"ORDER BY anon_1.anon_2_users_id",
)