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 |
|
Undocumented |
Class |
|
A token propagated throughout the course of a chain of attribute events. |
Class |
|
internal implementation for instrumented attributes. |
Class |
|
A collection-holding attribute that instruments changes in membership. |
Class |
|
Undocumented |
Class |
|
A 3-tuple of added, unchanged and deleted values, representing the changes which have occurred on an instrumented attribute. |
Class |
|
Class bound instrumented attribute which adds basic :term:`descriptor` methods. |
Class |
|
Base class for :term:`descriptor` objects that intercept attribute events on behalf of a :class:`.MapperProperty` object. The actual :class:`.MapperProperty` is accessible via the :attr:`.QueryableAttribute... |
Class |
|
represents a scalar value-holding InstrumentedAttribute. |
Class |
|
represents a scalar-holding InstrumentedAttribute, where the target object is also instrumented. |
Function | backref |
Apply listeners to synchronize a two-way relationship. |
Function | create |
Create an QueryableAttribute / user descriptor hybrid. |
Function | del |
Delete the value of an attribute, firing history events. |
Function | flag |
Mark an instance as 'dirty' without any specific attribute mentioned. |
Function | flag |
Mark an attribute on an instance as 'modified'. |
Function | get |
Get the value of an attribute, firing any callables required. |
Function | get |
Return a :class:`.History` record for the given object and attribute key. |
Function | get |
Undocumented |
Function | has |
TODO |
Function | init |
Initialize a collection attribute and return the collection adapter. |
Function | init |
Initialize a collection attribute and return the collection adapter. |
Function | register |
Undocumented |
Function | register |
Undocumented |
Function | register |
Undocumented |
Function | set |
Set the value of an attribute, firing history events. |
Function | set |
Set the value of an attribute with no history events. |
Function | unregister |
Undocumented |
Constant | HISTORY |
Undocumented |
Constant | OP |
Undocumented |
Constant | OP |
Undocumented |
Constant | OP |
Undocumented |
Constant | OP |
Undocumented |
Constant | OP |
Undocumented |
Function | _is |
Undocumented |
Function | _queryable |
Undocumented |
Constant | _NO |
Undocumented |
Constant | _NO |
Undocumented |
Constant | _UNKNOWN |
Undocumented |
Type Variable | _T |
Undocumented |
Type Alias | _ |
Undocumented |
Create an QueryableAttribute / user descriptor hybrid. Returns a new QueryableAttribute type that delegates descriptor behavior and getattr() to the given descriptor.
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 :meth:`.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 :meth:`.SessionEvents.before_flush` handler will be able to see the object in the :attr:`.Session.dirty` collection and may establish changes on it, which will then be included in the SQL emitted. .. versionadded:: 1.2 .. seealso:: :func:`.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 :class:`.InvalidRequestError` is raised. To mark an object "dirty" without referring to any specific attribute so that it is considered within a flush, use the :func:`.attributes.flag_dirty` call. .. seealso:: :func:`.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 :class:`.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 :class:`.Session` flushes changes to the current database transaction. .. note:: Prefer to use the :attr:`.AttributeState.history` and :meth:`.AttributeState.load_history` accessors to retrieve the :class:`.History` for instance attributes. :param obj: an object whose class is instrumented by the attributes package. :param key: string attribute name. :param passive: indicates loading behavior for the attribute if the value is not already present. This is a bitflag attribute, which defaults to the symbol :attr:`.PASSIVE_OFF` indicating all necessary SQL should be emitted. .. seealso:: :attr:`.AttributeState.history` :meth:`.AttributeState.load_history` - retrieve history using loader callables if the value is not locally present.
InstanceState[ Any]
, key: str
, passive: PassiveFlag
= PASSIVE_OFF) -> History
:
(source)
¶
Undocumented
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 :func:`~sqlalchemy.orm.attributes.set_committed_value`. :param obj: a mapped object :param key: string attribute name where the collection is located.
InstanceState[ Any]
, dict_: _InstanceDict
, key: str
) -> CollectionAdapter
:
(source)
¶
Initialize a collection attribute and return the collection adapter. Discards any existing collection which may be there.
Type[ _O]
, key: str
, *, comparator: interfaces.PropComparator[ _T]
, parententity: _InternalEntityType[ _O]
, doc: Optional[ str]
= None, **kw: Any
) -> InstrumentedAttribute[ _T]
:
(source)
¶
Undocumented
Type[ _O]
, key: str
, uselist: bool
= False, callable_: Optional[ _LoaderCallable]
= None, useobject: bool
= False, impl_class: Optional[ Type[ AttributeImpl]]
= None, backref: Optional[ str]
= None, **kw: Any
) -> QueryableAttribute[ Any]
:
(source)
¶
Undocumented
Type[ Any]
, key: str
, *, comparator: interfaces.PropComparator[ _T]
, parententity: _InternalEntityType[ Any]
, doc: Optional[ str]
= None) -> InstrumentedAttribute[ _T]
:
(source)
¶
Undocumented
object
, key: str
, value: Any
, initiator: Optional[ AttributeEventToken]
= None):
(source)
¶
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. :param instance: the object that will be modified :param key: string name of the attribute :param value: value to assign :param initiator: an instance of :class:`.Event` that would have been propagated from a previous event listener. This argument is used when the :func:`.set_attribute` function is being used within an existing event listening function where an :class:`.Event` object is being supplied; the object may be used to track the origin of the chain of events. .. versionadded:: 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.
AttributeImpl
) -> TypeGuard[ CollectionAttributeImpl]
:
(source)
¶
Undocumented
str
, mapped_class: Type[ _O]
, parententity: _InternalEntityType[ _O]
, entity: _ExternalEntityType[ Any]
) -> Any
:
(source)
¶
Undocumented