From 25fc9562f08fe26e4e2f6d4cf69c34b666f0180a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 10 Mar 2019 23:34:33 -0400 Subject: Clone internals for Select._correlate_except collection as well as _correlate Fixed bug where use of :func:`.with_polymorphic` or other aliased construct would not properly adapt when the aliased target were used as the :meth:`.Select.correlate_except` target of a subquery used inside of a :func:`.column_property`. This required a fix to the clause adaption mechanics to properly handle a selectable that shows up in the "correlate except" list, in a similar manner as which occurs for selectables that show up in the "correlate" list. This is ultimately a fairly fundamental bug that has lasted for a long time but it is hard to come across it. Fixes: #4537 Change-Id: Ibb97d4eea18b3c452aad519dd14919bfb84d422f --- lib/sqlalchemy/sql/selectable.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/sqlalchemy/sql/selectable.py') diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index cc6d2bcc5..d4528f0c3 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -3227,6 +3227,14 @@ class Select(HasPrefixes, HasSuffixes, GenerativeSelect): self._correlate = set(clone(f) for f in self._correlate).union( self._correlate ) + + # do something similar for _correlate_except - this is a more + # unusual case but same idea applies + if self._correlate_except: + self._correlate_except = set( + clone(f) for f in self._correlate_except + ).union(self._correlate_except) + # 4. clone other things. The difficulty here is that Column # objects are not actually cloned, and refer to their original # .table, resulting in the wrong "from" parent after a clone -- cgit v1.2.1