summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-03-18 11:59:16 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-03-18 13:12:34 -0400
commitdfce8c35d3f95c401957f4d0ddaf8c7f49f52ece (patch)
tree44bd505932dab87b629110c52afd1c05d497f307 /test/sql
parent3fec5028e695ad138aa46a0ae66c55e8bcb653f6 (diff)
downloadsqlalchemy-dfce8c35d3f95c401957f4d0ddaf8c7f49f52ece.tar.gz
Raise at Core / ORM concrete inh level for label overlap
Fixed regression where the :class:`.ConcreteBase` would fail to map at all when a mapped column name overlapped with the discriminator column name, producing an assertion error. The use case here did not function correctly in 1.3 as the polymorphic union would produce a query that ignored the discriminator column entirely, while emitting duplicate column warnings. As 1.4's architecture cannot easily reproduce this essentially broken behavior of 1.3 at the ``select()`` level right now, the use case now raises an informative error message instructing the user to use the ``.ConcreteBase._concrete_discriminator_name`` attribute to resolve the conflict. To assist with this configuration, ``.ConcreteBase._concrete_discriminator_name`` may be placed on the base class only where it will be automatically used by subclasses; previously this was not the case. Fixes: #6090 Change-Id: I8b7d01e4c9ea0dc97f30b8cd658b3505b24312a7
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_selectable.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py
index 762146a3d..458b8f782 100644
--- a/test/sql/test_selectable.py
+++ b/test/sql/test_selectable.py
@@ -49,6 +49,7 @@ from sqlalchemy.testing import in_
from sqlalchemy.testing import is_
from sqlalchemy.testing import is_not
from sqlalchemy.testing import ne_
+from sqlalchemy.testing.assertions import expect_raises_message
metadata = MetaData()
@@ -208,6 +209,36 @@ class SelectableTest(
checkparams={"param_1": 5},
)
+ @testing.combinations((True,), (False,))
+ def test_broken_select_same_named_explicit_cols(self, use_anon):
+ # this is issue #6090. the query is "wrong" and we dont know how
+ # to render this right now.
+ stmt = select(
+ table1.c.col1,
+ table1.c.col2,
+ literal_column("col2").label(None if use_anon else "col2"),
+ ).select_from(table1)
+
+ if use_anon:
+ self.assert_compile(
+ select(stmt.subquery()),
+ "SELECT anon_1.col1, anon_1.col2, anon_1.col2_1 FROM "
+ "(SELECT table1.col1 AS col1, table1.col2 AS col2, "
+ "col2 AS col2_1 FROM table1) AS anon_1",
+ )
+ else:
+ # the keys here are not critical as they are not what was
+ # requested anyway, maybe should raise here also.
+ eq_(stmt.selected_columns.keys(), ["col1", "col2", "col2_1"])
+ with expect_raises_message(
+ exc.InvalidRequestError,
+ "Label name col2 is being renamed to an anonymous "
+ "label due to "
+ "disambiguation which is not supported right now. Please use "
+ "unique names for explicit labels.",
+ ):
+ select(stmt.subquery()).compile()
+
def test_select_label_grouped_still_corresponds(self):
label = select(table1.c.col1).label("foo")
label2 = label.self_group()