From 71030d67bd7c7948ef4a4d868821703ef5a57476 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 5 Oct 2016 13:59:58 -0400 Subject: Propagate execution_options at compile stage Compiler can now set up execution options and additionally will propagate autocommit from embedded CTEs. Change-Id: I19db7b8fe4d84549ea95342e8d2040189fed1bbe Fixes: #3805 --- lib/sqlalchemy/sql/compiler.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 6527eb8c6..b8c897cb9 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -168,6 +168,12 @@ class Compiled(object): _cached_metadata = None + execution_options = util.immutabledict() + """ + Execution options propagated from the statement. In some cases, + sub-elements of the statement can modify these. + """ + def __init__(self, dialect, statement, bind=None, schema_translate_map=None, compile_kwargs=util.immutabledict()): @@ -205,6 +211,8 @@ class Compiled(object): if statement is not None: self.statement = statement self.can_execute = statement.supports_execution + if self.can_execute: + self.execution_options = statement._execution_options self.string = self.process(self.statement, **compile_kwargs) @util.deprecated("0.7", ":class:`.Compiled` objects now compile " @@ -364,6 +372,7 @@ class SQLCompiler(Compiled): insert_prefetch = update_prefetch = () + def __init__(self, dialect, statement, column_keys=None, inline=False, **kwargs): """Construct a new :class:`.SQLCompiler` object. @@ -1296,6 +1305,12 @@ class SQLCompiler(Compiled): self.ctes_by_name[cte_name] = cte + # look for embedded DML ctes and propagate autocommit + if 'autocommit' in cte.element._execution_options and \ + 'autocommit' not in self.execution_options: + self.execution_options = self.execution_options.union( + {"autocommit": cte.element._execution_options['autocommit']}) + if cte._cte_alias is not None: orig_cte = cte._cte_alias if orig_cte not in self.ctes: -- cgit v1.2.1