diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-08-05 17:25:05 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-08-05 17:26:00 -0400 |
| commit | 85fa363c846f4ed287565c43c32e2cca29470e25 (patch) | |
| tree | 21205f1e8e2064f4527b81adb402ddd9c0e20d38 /test/sql | |
| parent | f08576274417bb1a836c072ff240bd5ad2ab40b7 (diff) | |
| download | sqlalchemy-85fa363c846f4ed287565c43c32e2cca29470e25.tar.gz | |
deep compare CTEs before considering them conflicting
Fixed issue where referencing a CTE multiple times in conjunction with a
polymorphic SELECT could result in multiple "clones" of the same CTE being
constructed, which would then trigger these two CTEs as duplicates. To
resolve, the two CTEs are deep-compared when this occurs to ensure that
they are equivalent, then are treated as equivalent.
Fixes: #8357
Change-Id: I1f634a9cf7a6c4256912aac1a00506aecea3b0e2
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_cte.py | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/test/sql/test_cte.py b/test/sql/test_cte.py index d1d01a5c7..f369518fc 100644 --- a/test/sql/test_cte.py +++ b/test/sql/test_cte.py @@ -489,20 +489,38 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): "SELECT cs1.x, cs2.x AS x_1 FROM bar AS cs1, cte AS cs2", ) - def test_conflicting_names(self): + @testing.combinations(True, False, argnames="identical") + @testing.combinations(True, False, argnames="use_clone") + def test_conflicting_names(self, identical, use_clone): """test a flat out name conflict.""" s1 = select(1) c1 = s1.cte(name="cte1", recursive=True) - s2 = select(1) - c2 = s2.cte(name="cte1", recursive=True) + if use_clone: + c2 = c1._clone() + if not identical: + c2 = c2.union(select(2)) + else: + if identical: + s2 = select(1) + else: + s2 = select(column("q")) + c2 = s2.cte(name="cte1", recursive=True) s = select(c1, c2) - assert_raises_message( - CompileError, - "Multiple, unrelated CTEs found " "with the same name: 'cte1'", - s.compile, - ) + + if use_clone and identical: + self.assert_compile( + s, + 'WITH RECURSIVE cte1("1") AS (SELECT 1) SELECT cte1.1, ' + 'cte1.1 AS "1_1" FROM cte1', + ) + else: + assert_raises_message( + CompileError, + "Multiple, unrelated CTEs found " "with the same name: 'cte1'", + s.compile, + ) def test_with_recursive_no_name_currently_buggy(self): s1 = select(1) |
