Execute the statement represented by this :class:`.ORMExecuteState`, without re-invoking events that have already proceeded. This method essentially performs a re-entrant execution of the current statement for which the :meth:`.SessionEvents.do_orm_execute` event is
(
self,
statement: Optional[Executable] = None,
params: Optional[_CoreAnyExecuteParams] = None,
execution_options: Optional[OrmExecuteOptionsParameter] = None,
bind_arguments: Optional[_BindArguments] = None,
)
| 379 | return self._events_todo[self._starting_event_idx + 1 :] |
| 380 | |
| 381 | def invoke_statement( |
| 382 | self, |
| 383 | statement: Optional[Executable] = None, |
| 384 | params: Optional[_CoreAnyExecuteParams] = None, |
| 385 | execution_options: Optional[OrmExecuteOptionsParameter] = None, |
| 386 | bind_arguments: Optional[_BindArguments] = None, |
| 387 | ) -> Result[Unpack[TupleAny]]: |
| 388 | """Execute the statement represented by this |
| 389 | :class:`.ORMExecuteState`, without re-invoking events that have |
| 390 | already proceeded. |
| 391 | |
| 392 | This method essentially performs a re-entrant execution of the current |
| 393 | statement for which the :meth:`.SessionEvents.do_orm_execute` event is |
| 394 | being currently invoked. The use case for this is for event handlers |
| 395 | that want to override how the ultimate |
| 396 | :class:`_engine.Result` object is returned, such as for schemes that |
| 397 | retrieve results from an offline cache or which concatenate results |
| 398 | from multiple executions. |
| 399 | |
| 400 | When the :class:`_engine.Result` object is returned by the actual |
| 401 | handler function within :meth:`_orm.SessionEvents.do_orm_execute` and |
| 402 | is propagated to the calling |
| 403 | :meth:`_orm.Session.execute` method, the remainder of the |
| 404 | :meth:`_orm.Session.execute` method is preempted and the |
| 405 | :class:`_engine.Result` object is returned to the caller of |
| 406 | :meth:`_orm.Session.execute` immediately. |
| 407 | |
| 408 | :param statement: optional statement to be invoked, in place of the |
| 409 | statement currently represented by :attr:`.ORMExecuteState.statement`. |
| 410 | |
| 411 | :param params: optional dictionary of parameters or list of parameters |
| 412 | which will be merged into the existing |
| 413 | :attr:`.ORMExecuteState.parameters` of this :class:`.ORMExecuteState`. |
| 414 | |
| 415 | .. versionchanged:: 2.0 a list of parameter dictionaries is accepted |
| 416 | for executemany executions. |
| 417 | |
| 418 | :param execution_options: optional dictionary of execution options |
| 419 | will be merged into the existing |
| 420 | :attr:`.ORMExecuteState.execution_options` of this |
| 421 | :class:`.ORMExecuteState`. |
| 422 | |
| 423 | :param bind_arguments: optional dictionary of bind_arguments |
| 424 | which will be merged amongst the current |
| 425 | :attr:`.ORMExecuteState.bind_arguments` |
| 426 | of this :class:`.ORMExecuteState`. |
| 427 | |
| 428 | :return: a :class:`_engine.Result` object with ORM-level results. |
| 429 | |
| 430 | .. seealso:: |
| 431 | |
| 432 | :ref:`do_orm_execute_re_executing` - background and examples on the |
| 433 | appropriate usage of :meth:`_orm.ORMExecuteState.invoke_statement`. |
| 434 | |
| 435 | |
| 436 | """ |
| 437 | |
| 438 | if statement is None: |