class documentation

Represents a call to the :meth:`_orm.Session.execute` method, as passed to the :meth:`.SessionEvents.do_orm_execute` event hook. .. versionadded:: 1.4 .. seealso:: :ref:`session_execute_events` - top level documentation on how to use :meth:`_orm.SessionEvents.do_orm_execute`

Method __init__ Construct a new :class:`_orm.ORMExecuteState`.
Method invoke_statement Execute the statement represented by this :class:`.ORMExecuteState`, without re-invoking events that have already proceeded.
Method update_execution_options Update the local execution options with new values.
Class Variable __slots__ Undocumented
Instance Variable bind_arguments The dictionary passed as the :paramref:`_orm.Session.execute.bind_arguments` dictionary.
Instance Variable execution_options The complete dictionary of current execution options.
Instance Variable local_execution_options Dictionary view of the execution options passed to the :meth:`.Session.execute` method.
Instance Variable parameters Dictionary of parameters that was passed to :meth:`_orm.Session.execute`.
Instance Variable session The :class:`_orm.Session` in use.
Instance Variable statement The SQL statement being invoked.
Property all_mappers Return a sequence of all :class:`_orm.Mapper` objects that are involved at the top level of this statement.
Property bind_mapper Return the :class:`_orm.Mapper` that is the primary "bind" mapper.
Property is_column_load Return True if the operation is refreshing column-oriented attributes on an existing ORM object.
Property is_delete return True if this is a DELETE operation.
Property is_executemany return True if the parameters are a multi-element list of dictionaries with more than one dictionary.
Property is_insert return True if this is an INSERT operation.
Property is_orm_statement return True if the operation is an ORM statement.
Property is_relationship_load Return True if this load is loading objects on behalf of a relationship.
Property is_select return True if this is a SELECT operation.
Property is_update return True if this is an UPDATE operation.
Property lazy_loaded_from An :class:`.InstanceState` that is using this statement execution for a lazy load operation.
Property load_options Return the load_options that will be used for this execution.
Property loader_strategy_path Return the :class:`.PathRegistry` for the current load path.
Property update_delete_options Return the update_delete_options that will be used for this execution.
Property user_defined_options The sequence of :class:`.UserDefinedOptions` that have been associated with the statement being invoked.
Method _orm_compile_options Undocumented
Method _remaining_events Undocumented
Class Variable _starting_event_idx Undocumented
Class Variable _update_execution_options Undocumented
Instance Variable _compile_state_cls Undocumented
Instance Variable _events_todo Undocumented
Property _is_crud Undocumented
Property _non_compile_orm_options Undocumented

Inherited from MemoizedSlots:

Method __getattr__ Undocumented
Method _fallback_getattr Undocumented
def __init__(self, session: Session, statement: Executable, parameters: Optional[_CoreAnyExecuteParams], execution_options: _ExecuteOptions, bind_arguments: _BindArguments, compile_state_cls: Optional[Type[ORMCompileState]], events_todo: List[_InstanceLevelDispatch[Session]]): (source)

Construct a new :class:`_orm.ORMExecuteState`. this object is constructed internally.

def invoke_statement(self, statement: Optional[Executable] = None, params: Optional[_CoreAnyExecuteParams] = None, execution_options: Optional[OrmExecuteOptionsParameter] = None, bind_arguments: Optional[_BindArguments] = None) -> Result[Any]: (source)

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 being currently invoked. The use case for this is for event handlers that want to override how the ultimate :class:`_engine.Result` object is returned, such as for schemes that retrieve results from an offline cache or which concatenate results from multiple executions. When the :class:`_engine.Result` object is returned by the actual handler function within :meth:`_orm.SessionEvents.do_orm_execute` and is propagated to the calling :meth:`_orm.Session.execute` method, the remainder of the :meth:`_orm.Session.execute` method is preempted and the :class:`_engine.Result` object is returned to the caller of :meth:`_orm.Session.execute` immediately. :param statement: optional statement to be invoked, in place of the statement currently represented by :attr:`.ORMExecuteState.statement`. :param params: optional dictionary of parameters or list of parameters which will be merged into the existing :attr:`.ORMExecuteState.parameters` of this :class:`.ORMExecuteState`. .. versionchanged:: 2.0 a list of parameter dictionaries is accepted for executemany executions. :param execution_options: optional dictionary of execution options will be merged into the existing :attr:`.ORMExecuteState.execution_options` of this :class:`.ORMExecuteState`. :param bind_arguments: optional dictionary of bind_arguments which will be merged amongst the current :attr:`.ORMExecuteState.bind_arguments` of this :class:`.ORMExecuteState`. :return: a :class:`_engine.Result` object with ORM-level results. .. seealso:: :ref:`do_orm_execute_re_executing` - background and examples on the appropriate usage of :meth:`_orm.ORMExecuteState.invoke_statement`.

def update_execution_options(self, **opts: Any): (source)

Update the local execution options with new values.

bind_arguments = (source)

The dictionary passed as the :paramref:`_orm.Session.execute.bind_arguments` dictionary. This dictionary may be used by extensions to :class:`_orm.Session` to pass arguments that will assist in determining amongst a set of database connections which one should be used to invoke this statement.

execution_options = (source)

The complete dictionary of current execution options. This is a merge of the statement level options with the locally passed execution options. .. seealso:: :attr:`_orm.ORMExecuteState.local_execution_options` :meth:`_sql.Executable.execution_options` :ref:`orm_queryguide_execution_options`

local_execution_options = (source)

Dictionary view of the execution options passed to the :meth:`.Session.execute` method. This does not include options that may be associated with the statement being invoked. .. seealso:: :attr:`_orm.ORMExecuteState.execution_options`

parameters = (source)

Dictionary of parameters that was passed to :meth:`_orm.Session.execute`.

The :class:`_orm.Session` in use.

statement = (source)

The SQL statement being invoked. For an ORM selection as would be retrieved from :class:`_orm.Query`, this is an instance of :class:`_sql.select` that was generated from the ORM query.

Return a sequence of all :class:`_orm.Mapper` objects that are involved at the top level of this statement. By "top level" we mean those :class:`_orm.Mapper` objects that would be represented in the result set rows for a :func:`_sql.select` query, or for a :func:`_dml.update` or :func:`_dml.delete` query, the mapper that is the main subject of the UPDATE or DELETE. .. versionadded:: 1.4.0b2 .. seealso:: :attr:`_orm.ORMExecuteState.bind_mapper`

Return the :class:`_orm.Mapper` that is the primary "bind" mapper. For an :class:`_orm.ORMExecuteState` object invoking an ORM statement, that is, the :attr:`_orm.ORMExecuteState.is_orm_statement` attribute is ``True``, this attribute will return the :class:`_orm.Mapper` that is considered to be the "primary" mapper of the statement. The term "bind mapper" refers to the fact that a :class:`_orm.Session` object may be "bound" to multiple :class:`_engine.Engine` objects keyed to mapped classes, and the "bind mapper" determines which of those :class:`_engine.Engine` objects would be selected. For a statement that is invoked against a single mapped class, :attr:`_orm.ORMExecuteState.bind_mapper` is intended to be a reliable way of getting this mapper. .. versionadded:: 1.4.0b2 .. seealso:: :attr:`_orm.ORMExecuteState.all_mappers`

@property
is_column_load: bool = (source)

Return True if the operation is refreshing column-oriented attributes on an existing ORM object. This occurs during operations such as :meth:`_orm.Session.refresh`, as well as when an attribute deferred by :func:`_orm.defer` is being loaded, or an attribute that was expired either directly by :meth:`_orm.Session.expire` or via a commit operation is being loaded. Handlers will very likely not want to add any options to queries when such an operation is occurring as the query should be a straight primary key fetch which should not have any additional WHERE criteria, and loader options travelling with the instance will have already been added to the query. .. versionadded:: 1.4.0b2 .. seealso:: :attr:`_orm.ORMExecuteState.is_relationship_load`

return True if this is a DELETE operation.

@property
is_executemany: bool = (source)

return True if the parameters are a multi-element list of dictionaries with more than one dictionary. .. versionadded:: 2.0

return True if this is an INSERT operation.

@property
is_orm_statement: bool = (source)

return True if the operation is an ORM statement. This indicates that the select(), insert(), update(), or delete() being invoked contains ORM entities as subjects. For a statement that does not have ORM entities and instead refers only to :class:`.Table` metadata, it is invoked as a Core SQL statement and no ORM-level automation takes place.

@property
is_relationship_load: bool = (source)

Return True if this load is loading objects on behalf of a relationship. This means, the loader in effect is either a LazyLoader, SelectInLoader, SubqueryLoader, or similar, and the entire SELECT statement being emitted is on behalf of a relationship load. Handlers will very likely not want to add any options to queries when such an operation is occurring, as loader options are already capable of being propagated to relationship loaders and should be already present. .. seealso:: :attr:`_orm.ORMExecuteState.is_column_load`

return True if this is a SELECT operation.

return True if this is an UPDATE operation.

An :class:`.InstanceState` that is using this statement execution for a lazy load operation. The primary rationale for this attribute is to support the horizontal sharding extension, where it is available within specific query execution time hooks created by this extension. To that end, the attribute is only intended to be meaningful at **query execution time**, and importantly not any time prior to that, including query compilation time.

Return the load_options that will be used for this execution.

@property
loader_strategy_path: Optional[PathRegistry] = (source)

Return the :class:`.PathRegistry` for the current load path. This object represents the "path" in a query along relationships when a particular object or collection is being loaded.

Return the update_delete_options that will be used for this execution.

The sequence of :class:`.UserDefinedOptions` that have been associated with the statement being invoked.

def _remaining_events(self) -> List[_InstanceLevelDispatch[Session]]: (source)

Undocumented

_starting_event_idx: int = (source)

Undocumented

_update_execution_options: Optional[_ExecuteOptions] = (source)

Undocumented

_compile_state_cls = (source)

Undocumented

_events_todo = (source)

Undocumented

Undocumented

@property
_non_compile_orm_options: Sequence[ORMOption] = (source)

Undocumented