summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-10-05 13:59:58 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-10-05 16:47:31 -0400
commit71030d67bd7c7948ef4a4d868821703ef5a57476 (patch)
tree7872a83afaafc414fa13d572a634dd690f4d9824 /lib/sqlalchemy/sql/compiler.py
parent09b685b24b19636e11169c181b45333f9739ca35 (diff)
downloadsqlalchemy-71030d67bd7c7948ef4a4d868821703ef5a57476.tar.gz
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
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py15
1 files changed, 15 insertions, 0 deletions
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: