Defines instrumentation for class attributes and their interaction with instances.
This module is usually not directly visible to user applications, but defines a large part of the ORM's interactivity.
Class | AttributeEvent |
A token propagated throughout the course of a chain of attribute events. |
Class | History |
A 3-tuple of added, unchanged and deleted values, representing the changes which have occurred on an instrumented attribute. |
Class | InstrumentedAttribute |
Class bound instrumented attribute which adds basic :term:`descriptor` methods. |
Class | Mapped |
Represent an ORM mapped :term:`descriptor` attribute for typing purposes. |
Class | QueryableAttribute |
No summary |
Function | del_attribute |
Delete the value of an attribute, firing history events. |
Function | flag_dirty |
Mark an instance as 'dirty' without any specific attribute mentioned. |
Function | flag_modified |
Mark an attribute on an instance as 'modified'. |
Function | get_attribute |
Get the value of an attribute, firing any callables required. |
Function | get_history |
Return a .History record for the given object and attribute key. |
Function | init_collection |
Initialize a collection attribute and return the collection adapter. |
Function | set_attribute |
Set the value of an attribute, firing history events. |
Function | set_committed_value |
Set the value of an attribute with no history events. |
Constant | HISTORY_BLANK |
Undocumented |
Constant | NO_KEY |
Undocumented |
Constant | OP_APPEND |
Undocumented |
Constant | OP_BULK_REPLACE |
Undocumented |
Constant | OP_MODIFIED |
Undocumented |
Constant | OP_REMOVE |
Undocumented |
Constant | OP_REPLACE |
Undocumented |
Variable | HasEntityNamespace |
Undocumented |
Class | AttributeImpl |
internal implementation for instrumented attributes. |
Class | CollectionAttributeImpl |
A collection-holding attribute that instruments changes in membership. |
Class | NoKey |
Undocumented |
Class | ScalarAttributeImpl |
represents a scalar value-holding InstrumentedAttribute. |
Class | ScalarObjectAttributeImpl |
represents a scalar-holding InstrumentedAttribute, where the target object is also instrumented. |
Function | _queryable_attribute_unreduce |
Undocumented |
Function | backref_listeners |
Apply listeners to synchronize a two-way relationship. |
Function | create_proxied_attribute |
Create an QueryableAttribute / user descriptor hybrid. |
Function | get_state_history |
Undocumented |
Function | has_parent |
TODO |
Function | init_state_collection |
Initialize a collection attribute and return the collection adapter. |
Function | register_attribute |
Undocumented |
Function | register_attribute_impl |
Undocumented |
Function | register_descriptor |
Undocumented |
Function | unregister_attribute |
Undocumented |
Constant | _NO_HISTORY |
Undocumented |
Constant | _NO_STATE_SYMBOLS |
Undocumented |
Constant | _T |
Undocumented |
Variable | _Generic_T |
Undocumented |
Delete the value of an attribute, firing history events.
This function may be used regardless of instrumentation applied directly to the class, i.e. no descriptors are required. Custom attribute management schemes will need to make usage of this method to establish attribute state as understood by SQLAlchemy.
Mark an instance as 'dirty' without any specific attribute mentioned.
This is a special operation that will allow the object to travel through
the flush process for interception by events such as
.SessionEvents.before_flush
. Note that no SQL will be emitted in
the flush process for an object that has no changes, even if marked dirty
via this method. However, a .SessionEvents.before_flush
handler
will be able to see the object in the .Session.dirty
collection and
may establish changes on it, which will then be included in the SQL
emitted.
See Also
.attributes.flag_modified
Mark an attribute on an instance as 'modified'.
This sets the 'modified' flag on the instance and
establishes an unconditional change event for the given attribute.
The attribute must have a value present, else an
.InvalidRequestError
is raised.
To mark an object "dirty" without referring to any specific attribute
so that it is considered within a flush, use the
.attributes.flag_dirty
call.
See Also
.attributes.flag_dirty
Get the value of an attribute, firing any callables required.
This function may be used regardless of instrumentation applied directly to the class, i.e. no descriptors are required. Custom attribute management schemes will need to make usage of this method to make usage of attribute state as understood by SQLAlchemy.
Return a .History
record for the given object
and attribute key.
This is the pre-flush history for a given attribute, which is
reset each time the .Session
flushes changes to the
current database transaction.
Note
Prefer to use the .AttributeState.history
and
.AttributeState.load_history
accessors to retrieve the
.History
for instance attributes.
See Also
.AttributeState.history
.AttributeState.load_history
- retrieve history
using loader callables if the value is not locally present.
Parameters | |
obj | an object whose class is instrumented by the attributes package. |
key | string attribute name. |
passive | indicates loading behavior for the attribute
if the value is not already present. This is a
bitflag attribute, which defaults to the symbol
.PASSIVE_OFF indicating all necessary SQL
should be emitted. |
Initialize a collection attribute and return the collection adapter.
This function is used to provide direct access to collection internals for a previously unloaded attribute. e.g.:
collection_adapter = init_collection(someobject, 'elements') for elem in values: collection_adapter.append_without_event(elem)
For an easier way to do the above, see
~sqlalchemy.orm.attributes.set_committed_value
.
Parameters | |
obj | a mapped object |
key | string attribute name where the collection is located. |
Set the value of an attribute, firing history events.
This function may be used regardless of instrumentation applied directly to the class, i.e. no descriptors are required. Custom attribute management schemes will need to make usage of this method to establish attribute state as understood by SQLAlchemy.
Parameters | |
instance | the object that will be modified |
key | string name of the attribute |
value | value to assign |
initiator | an instance of
New in version 1.2.3.
|
Set the value of an attribute with no history events.
Cancels any previous history present. The value should be a scalar value for scalar-holding attributes, or an iterable for any collection-holding attribute.
This is the same underlying method used when a lazy loader fires off and loads additional data from the database. In particular, this method can be used by application code which has loaded additional attributes or collections through separate queries, which can then be attached to an instance as though it were part of its original loaded state.
Create an QueryableAttribute / user descriptor hybrid.
Returns a new QueryableAttribute type that delegates descriptor behavior and getattr() to the given descriptor.
Initialize a collection attribute and return the collection adapter.
Discards any existing collection which may be there.