]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Fix recursive CTE to support nesting
authorEric Masseran <eric.masseran@gmail.com>
Fri, 8 Oct 2021 14:02:58 +0000 (10:02 -0400)
committermike bayer <mike_mp@zzzcomputing.com>
Tue, 12 Oct 2021 22:46:57 +0000 (22:46 +0000)
commitee9b8836a160484733baa556c5d3ade4810aa999
tree623c4fa6e17d2366934b931a9695f12dc1a34e9f
parentde9db9940fbcf32ccd93169d2ed6aa874869b84d
Fix recursive CTE to support nesting

Repaired issue in new :paramref:`_sql.HasCTE.cte.nesting` parameter
introduced with :ticket:`4123` where a recursive :class:`_sql.CTE` using
:paramref:`_sql.HasCTE.cte.recursive` in typical conjunction with UNION
would not compile correctly.  Additionally makes some adjustments so that
the :class:`_sql.CTE` construct creates a correct cache key.
Pull request courtesy Eric Masseran.

Fixes: #4123
> This has not been caught by the tests because the nesting recursive
queries there did not union against itself, eg there was only the i
root clause...

- Now tests are real recursive queries
- Add tests on aliased nested CTEs (recursive or not)
- Adapt the `_restates` attribute to use it as a reference
- Add some docs around to explain some variables usage

Closes: #7133
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7133
Pull-request-sha: 2633f34f7f5336a4a85bd3f71d07bca33ce27a2c

Change-Id: I15512c94e1bc1f52afc619d82057ca647d274e92
doc/build/changelog/unreleased_14/4123.rst [new file with mode: 0644]
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/selectable.py
test/sql/test_compare.py
test/sql/test_cte.py