From e486ef666f39f136c770c68db28f475d68e0173f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 12 Jul 2016 16:38:22 -0400 Subject: Work w/ prefetch even for selects, if present Fixed bug in new CTE feature for update/insert/delete stated as a CTE inside of an enclosing statement (typically SELECT) whereby oninsert and onupdate values weren't called upon for the embedded statement. This is accomplished by consulting prefetch for all statements. The collection is also broken into separate insert/update collections so that we don't need to consult toplevel self.isinsert to determine if the prefetch is for an insert or an update. What we don't yet test for are CTE combinations that have both insert/update in one statement, though these should now work in theory provided the underlying database supports such a statement. Change-Id: I3b6a860e22c86743c91c56a7ec751ff706f66f64 Fixes: #3745 --- lib/sqlalchemy/sql/compiler.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/sqlalchemy/sql/compiler.py') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 16ca7f959..095c84f03 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -359,6 +359,8 @@ class SQLCompiler(Compiled): True unless using an unordered TextAsFrom. """ + insert_prefetch = update_prefetch = () + def __init__(self, dialect, statement, column_keys=None, inline=False, **kwargs): """Construct a new :class:`.SQLCompiler` object. @@ -428,6 +430,10 @@ class SQLCompiler(Compiled): if self.positional and dialect.paramstyle == 'numeric': self._apply_numbered_params() + @property + def prefetch(self): + return list(self.insert_prefetch + self.update_prefetch) + @util.memoized_instancemethod def _init_cte_state(self): """Initialize collections related to CTEs only if -- cgit v1.2.1