diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-05-28 08:29:24 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-05-28 10:35:51 -0400 |
| commit | 460bed7cfd8a6dd035caff5f5b1b33edf96fa3bb (patch) | |
| tree | f693d05af509b210fe64255459b73bb425bb054e /test/sql | |
| parent | aaba0650d7410f579b2c14f8f1b0680a1d1852c4 (diff) | |
| download | sqlalchemy-460bed7cfd8a6dd035caff5f5b1b33edf96fa3bb.tar.gz | |
Fix adaption in AnnotatedLabel; repair needless expense in coercion
Fixed regression involving clause adaption of labeled ORM compound
elements, such as single-table inheritance discriminator expressions with
conditionals or CASE expressions, which could cause aliased expressions
such as those used in ORM join / joinedload operations to not be adapted
correctly, such as referring to the wrong table in the ON clause in a join.
This change also improves a performance bump that was located within the
process of invoking :meth:`_sql.Select.join` given an ORM attribute
as a target.
Fixes: #6550
Change-Id: I98906476f0cce6f41ea00b77c789baa818e9d167
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_external_traversal.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/sql/test_external_traversal.py b/test/sql/test_external_traversal.py index 9e829baea..3469dcb37 100644 --- a/test/sql/test_external_traversal.py +++ b/test/sql/test_external_traversal.py @@ -458,6 +458,34 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): select(f), "SELECT t1_1.col1 * :col1_1 AS anon_1 FROM t1 AS t1_1" ) + @testing.combinations( + (lambda t1: t1.c.col1, "t1_1.col1"), + (lambda t1: t1.c.col1 == "foo", "t1_1.col1 = :col1_1"), + ( + lambda t1: case((t1.c.col1 == "foo", "bar"), else_=t1.c.col1), + "CASE WHEN (t1_1.col1 = :col1_1) THEN :param_1 ELSE t1_1.col1 END", + ), + argnames="case, expected", + ) + @testing.combinations(False, True, argnames="label_") + @testing.combinations(False, True, argnames="annotate") + def test_annotated_label_cases(self, case, expected, label_, annotate): + """test #6550""" + + t1 = table("t1", column("col1")) + a1 = t1.alias() + + expr = case(t1=t1) + + if label_: + expr = expr.label(None) + if annotate: + expr = expr._annotate({"foo": "bar"}) + + adapted = sql_util.ClauseAdapter(a1).traverse(expr) + + self.assert_compile(adapted, expected) + @testing.combinations((null(),), (true(),)) def test_dont_adapt_singleton_elements(self, elem): """test :ticket:`6259`""" |
