--- /dev/null
+.. change::
+ :tags: bug, engine
+ :tickets: 13018
+
+ Fixed issue in the :meth:`.ConnectionEvents.after_cursor_execute` method
+ where the SQL statement and parameter list for an "insertmanyvalues"
+ operation sent to the event would not be the actual SQL / parameters just
+ emitted on the cursor, instead being the non-batched form of the statement
+ that's used as a template to generate the batched statements.
else:
do_execute_dispatch = ()
- if engine_events:
- _WORKAROUND_ISSUE_13018 = getattr(
- self, "_WORKAROUND_ISSUE_13018", False
- )
- else:
- _WORKAROUND_ISSUE_13018 = False
-
if self._echo:
stats = context._get_cache_stats() + " (insertmanyvalues)"
self.dispatch.after_cursor_execute(
self,
cursor,
- # TODO: this will be fixed by #13018
- sub_stmt if _WORKAROUND_ISSUE_13018 else str_statement,
- sub_params if _WORKAROUND_ISSUE_13018 else parameters,
+ sub_stmt,
+ sub_params,
context,
context.executemany,
)
def connection_execute(
conn, clauseelement, multiparams, params, execution_options
):
- conn._WORKAROUND_ISSUE_13018 = True
# grab the original statement + params before any cursor
# execution
orig[:] = clauseelement, multiparams, params
eq_(conn.scalar(select(1)), 1)
eng.dispose()
+ @testing.requires.insertmanyvalues
+ def test_cursor_execute_insertmanyvalues(self, connection, metadata):
+ """test #13018, that before_cursor_execute and after_cursor_execute
+ get the inner INSERT statements / params for an insertmanyvalues
+
+ """
+ canary = Mock()
+
+ t = Table(
+ "t",
+ metadata,
+ Column("id", Integer, primary_key=True),
+ Column("data", String(50)),
+ )
+ t.create(connection)
+
+ event.listen(connection, "before_cursor_execute", canary.bce)
+ event.listen(connection, "after_cursor_execute", canary.ace)
+
+ result = connection.execute(
+ t.insert().returning(
+ t.c.id, t.c.data, sort_by_parameter_order=True
+ ),
+ [{"data": f"d{i}"} for i in range(10)],
+ )
+ eq_(result.all(), [(i + 1, f"d{i}") for i in range(10)])
+
+ eq_(
+ [(c1.args[2], c1.args[3]) for c1 in canary.bce.mock_calls],
+ [(c1.args[2], c1.args[3]) for c1 in canary.ace.mock_calls],
+ )
+
class CompiledCacheTest(fixtures.TestBase):
__sparse_driver_backend__ = True