Extensible class instrumentation.
The sqlalchemy.ext.instrumentation
package provides for alternate
systems of class instrumentation within the ORM. Class instrumentation
refers to how the ORM places attributes on the class which maintain
data and track changes to that data, as well as event hooks installed
on the class.
Note
The extension package is provided for the benefit of integration with other object management packages, which already perform their own instrumentation. It is not intended for general use.
For examples of how the instrumentation extension is used, see the example :ref:`examples_instrumentation`.
Class | ExtendedInstrumentationRegistry |
Extends .InstrumentationFactory with additional bookkeeping, to accommodate multiple types of class managers. |
Class | InstrumentationManager |
User-defined class instrumentation extension. |
Constant | INSTRUMENTATION_MANAGER |
Attribute, elects custom instrumentation when present on a mapped class. |
Variable | instrumentation_finders |
An extensible sequence of callables which return instrumentation implementations |
Class | _ClassInstrumentationAdapter |
Adapts a user-defined InstrumentationManager to a ClassManager. |
Function | _install_instrumented_lookups |
No summary |
Function | _install_lookups |
Undocumented |
Function | _reinstall_default_lookups |
Restore simplified lookups. |
Function | find_native_user_instrumentation_hook |
Find user-specified instrumentation management for a class. |
Variable | _instrumentation_factory |
Undocumented |
str
=
Attribute, elects custom instrumentation when present on a mapped class.
Allows a class to specify a slightly or wildly different technique for tracking changes made to mapped attributes and collections.
Only one instrumentation implementation is allowed in a given object inheritance hierarchy.
The value of this attribute must be a callable and will be passed a class object. The callable must return one of:
- An instance of an
.InstrumentationManager
or subclass- An object implementing all or some of InstrumentationManager (TODO)
- A dictionary of callables, implementing all or some of the above (TODO)
- An instance of a
.ClassManager
or subclass
This attribute is consulted by SQLAlchemy instrumentation
resolution, once the sqlalchemy.ext.instrumentation
module
has been imported. If custom finders are installed in the global
instrumentation_finders list, they may or may not choose to honor this
attribute.
Value |
|
An extensible sequence of callables which return instrumentation implementations
When a class is registered, each callable will be passed a class object. If None is returned, the next finder in the sequence is consulted. Otherwise the return must be an instrumentation factory that follows the same guidelines as sqlalchemy.ext.instrumentation.INSTRUMENTATION_MANAGER.
By default, the only finder is find_native_user_instrumentation_hook, which searches for INSTRUMENTATION_MANAGER. If all finders return None, standard ClassManager instrumentation is used.
Replace global class/object management functions with ExtendedInstrumentationRegistry implementations, which allow multiple types of class managers to be present, at the cost of performance.
This function is called only by ExtendedInstrumentationRegistry and unit tests specific to this behavior.
The _reinstall_default_lookups() function can be called after this one to re-establish the default functions.