Class | ORMExecuteState |
Represents a call to the _orm.Session.execute method, as passed to the .SessionEvents.do_orm_execute event hook. |
Class | Session |
Manages persistence operations for ORM-mapped objects. |
Class | sessionmaker |
A configurable .Session factory. |
Class | SessionTransaction |
A .Session -level transaction. |
Constant | ACTIVE |
Undocumented |
Constant | CLOSED |
Undocumented |
Constant | COMMITTED |
Undocumented |
Constant | DEACTIVE |
Undocumented |
Constant | PREPARED |
Undocumented |
Class | _SessionClassMethods |
Class-level methods for .Session , .sessionmaker . |
Function | _state_session |
Given an .InstanceState , return the .Session associated, if any. |
Function | close_all_sessions |
Close all sessions in memory. |
Function | make_transient |
Alter the state of the given instance so that it is :term:`transient`. |
Function | make_transient_to_detached |
Make the given transient instance :term:`detached`. |
Function | object_session |
Return the .Session to which the given instance belongs. |
Variable | _new_sessionid |
Undocumented |
Variable | _sessions |
Weak-referencing dictionary of .Session objects. |
Close all sessions in memory.
This function consults a global registry of all .Session
objects
and calls .Session.close
on them, which resets them to a clean
state.
This function is not for general use but may be useful for test suites within the teardown scheme.
Alter the state of the given instance so that it is :term:`transient`.
Note
.make_transient
is a special-case function for
advanced use cases only.
The given mapped instance is assumed to be in the :term:`persistent` or
:term:`detached` state. The function will remove its association with any
.Session
as well as its .InstanceState.identity
. The
effect is that the object will behave as though it were newly constructed,
except retaining any attribute / collection values that were loaded at the
time of the call. The .InstanceState.deleted
flag is also reset
if this object had been deleted as a result of using
.Session.delete
.
Warning
.make_transient
does not "unexpire" or otherwise eagerly
load ORM-mapped attributes that are not currently loaded at the time
the function is called. This includes attributes which:
.Session.expire
.Session.commit
After .make_transient
is called, unloaded attributes such
as those above will normally resolve to the value None when
accessed, or an empty collection for a collection-oriented attribute.
As the object is transient and un-associated with any database
identity, it will no longer retrieve these values.
See Also
.make_transient_to_detached
Make the given transient instance :term:`detached`.
Note
.make_transient_to_detached
is a special-case function for
advanced use cases only.
All attribute history on the given instance will be reset as though the instance were freshly loaded from a query. Missing attributes will be marked as expired. The primary key attributes of the object, which are required, will be made into the "key" of the instance.
The object can then be added to a session, or merged possibly with the load=False flag, at which point it will look as if it were loaded that way, without emitting SQL.
This is a special use case function that differs from a normal
call to .Session.merge
in that a given persistent state
can be manufactured without any SQL calls.
See Also
.make_transient
.Session.enable_relationship_loading