class documentation

class Mutable(MutableBase):

Known subclasses: sqlalchemy.ext.mutable.MutableDict, sqlalchemy.ext.mutable.MutableList, sqlalchemy.ext.mutable.MutableSet

View In Hierarchy

Mixin that defines transparent propagation of change events to a parent object.

See the example in :ref:`mutable_scalars` for usage information.

Class Method as​_mutable Associate a SQL type with this mutable Python type.
Class Method associate​_with Associate this wrapper with all future mapped columns of the given type.
Class Method associate​_with​_attribute Establish this type as a mutation listener for the given mapped descriptor.
Method changed Subclasses should call this method whenever change events occur.

Inherited from MutableBase:

Class Method coerce Given a value, coerce it into the target type.
Class Method ​_get​_listen​_keys Given a descriptor attribute, return a set() of the attribute keys which indicate a change in the state of this attribute.
Class Method ​_listen​_on​_attribute Establish this type as a mutation listener for the given mapped descriptor.
Property ​_parents Dictionary of parent object's .InstanceState->attribute name on the parent.
@classmethod
def as_mutable(cls, sqltype):

Associate a SQL type with this mutable Python type.

This establishes listeners that will detect ORM mappings against the given type, adding mutation event trackers to those mappings.

The type is returned, unconditionally as an instance, so that .as_mutable can be used inline:

Table('mytable', metadata,
    Column('id', Integer, primary_key=True),
    Column('data', MyMutableType.as_mutable(PickleType))
)

Note that the returned type is always an instance, even if a class is given, and that only columns which are declared specifically with that type instance receive additional instrumentation.

To associate a particular mutable type with all occurrences of a particular type, use the .Mutable.associate_with classmethod of the particular .Mutable subclass to establish a global association.

Warning

The listeners established by this method are global to all mappers, and are not garbage collected. Only use .as_mutable for types that are permanent to an application, not with ad-hoc types else this will cause unbounded growth in memory usage.

@classmethod
def associate_with(cls, sqltype):

Associate this wrapper with all future mapped columns of the given type.

This is a convenience method that calls associate_with_attribute automatically.

Warning

The listeners established by this method are global to all mappers, and are not garbage collected. Only use .associate_with for types that are permanent to an application, not with ad-hoc types else this will cause unbounded growth in memory usage.

@classmethod
def associate_with_attribute(cls, attribute):
Establish this type as a mutation listener for the given mapped descriptor.
def changed(self):
Subclasses should call this method whenever change events occur.