From: Mike Bayer Date: Mon, 24 Feb 2020 19:45:38 +0000 (-0500) Subject: Remove needless clauseelement check for batch X-Git-Tag: rel_1_3_14~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2b51f037517c40c7c450448ea83afb7bd889c55;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Remove needless clauseelement check for batch Also document more detail as to why SQL expression support is not turned on for batch. Fixes: #5165 Change-Id: Ia93bbf75f22b8781400086c45b86a60ef9cec360 (cherry picked from commit 88c23da948e76b1c273b6c48389d6671878696eb) --- diff --git a/doc/build/orm/persistence_techniques.rst b/doc/build/orm/persistence_techniques.rst index 0a40e77956..34703bfbe2 100644 --- a/doc/build/orm/persistence_techniques.rst +++ b/doc/build/orm/persistence_techniques.rst @@ -772,7 +772,10 @@ are **not available** when using these methods: * Functionality related to primary key mutation, ON UPDATE cascade -* SQL expression inserts / updates (e.g. :ref:`flush_embedded_sql_expressions`) +* SQL expression inserts / updates (e.g. :ref:`flush_embedded_sql_expressions`) - + having to evaluate these would prevent INSERT and UPDATE statements from + being batched together in a straightforward way for a single executemany() + call as they alter the SQL compilation of the statement itself. * ORM events such as :meth:`.MapperEvents.before_insert`, etc. The bulk session methods have no event support. diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py index 79e7c89c33..28a6120683 100644 --- a/lib/sqlalchemy/orm/persistence.py +++ b/lib/sqlalchemy/orm/persistence.py @@ -502,9 +502,8 @@ def _collect_insert_commands( col = propkey_to_col[propkey] if value is None and col not in eval_none and not render_nulls: continue - elif ( - not bulk - and hasattr(value, "__clause_element__") + elif not bulk and ( + hasattr(value, "__clause_element__") or isinstance(value, sql.ClauseElement) ): value_params[col] = (