summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
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
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')
-rw-r--r--lib/sqlalchemy/engine/default.py4
-rw-r--r--lib/sqlalchemy/sql/compiler.py15
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py
index 891103ee0..05a993918 100644
--- a/lib/sqlalchemy/engine/default.py
+++ b/lib/sqlalchemy/engine/default.py
@@ -522,7 +522,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext):
self.compiled = compiled = compiled_ddl
self.isddl = True
- self.execution_options = compiled.statement._execution_options
+ self.execution_options = compiled.execution_options
if connection._execution_options:
self.execution_options = dict(self.execution_options)
self.execution_options.update(connection._execution_options)
@@ -559,7 +559,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext):
# we get here
assert compiled.can_execute
- self.execution_options = compiled.statement._execution_options.union(
+ self.execution_options = compiled.execution_options.union(
connection._execution_options)
self.result_column_struct = (
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: