class MutableBase: (source)
Known subclasses: sqlalchemy.ext.mutable.Mutable
, sqlalchemy.ext.mutable.MutableComposite
Common base class to :class:`.Mutable` and :class:`.MutableComposite`.
Class Method | coerce |
Given a value, coerce it into the target type. |
Class Method | _get |
Given a descriptor attribute, return a ``set()`` of the attribute keys which indicate a change in the state of this attribute. |
Class Method | _listen |
Establish this type as a mutation listener for the given mapped descriptor. |
Property | _parents |
Dictionary of parent object's :class:`.InstanceState`->attribute name on the parent. |
sqlalchemy.ext.mutable.MutableDict
, sqlalchemy.ext.mutable.MutableList
, sqlalchemy.ext.mutable.MutableSet
Given a value, coerce it into the target type. Can be overridden by custom subclasses to coerce incoming data into a particular type. By default, raises ``ValueError``. This method is called in different scenarios depending on if the parent class is of type :class:`.Mutable` or of type :class:`.MutableComposite`. In the case of the former, it is called for both attribute-set operations as well as during ORM loading operations. For the latter, it is only called during attribute-set operations; the mechanics of the :func:`.composite` construct handle coercion during load operations. :param key: string name of the ORM-mapped attribute being set. :param value: the incoming value. :return: the method should return the coerced value, or raise ``ValueError`` if the coercion cannot be completed.
sqlalchemy.ext.mutable.MutableComposite
Given a descriptor attribute, return a ``set()`` of the attribute keys which indicate a change in the state of this attribute. This is normally just ``set([attribute.key])``, but can be overridden to provide for additional keys. E.g. a :class:`.MutableComposite` augments this set with the attribute keys associated with the columns that comprise the composite value. This collection is consulted in the case of intercepting the :meth:`.InstanceEvents.refresh` and :meth:`.InstanceEvents.refresh_flush` events, which pass along a list of attribute names that have been refreshed; the list is compared against this set to determine if action needs to be taken. .. versionadded:: 1.0.5
def _listen_on_attribute(cls, attribute:
QueryableAttribute[ Any]
, coerce: bool
, parent_cls: _ExternalEntityType[ Any]
):
(source)
¶
Establish this type as a mutation listener for the given mapped descriptor.
Dictionary of parent object's :class:`.InstanceState`->attribute name on the parent. This attribute is a so-called "memoized" property. It initializes itself with a new ``weakref.WeakKeyDictionary`` the first time it is accessed, returning the same object upon subsequent access. .. versionchanged:: 1.4 the :class:`.InstanceState` is now used as the key in the weak dictionary rather than the instance itself.