diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-08-29 16:15:41 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-08-29 16:15:41 +0000 |
| commit | 4c6c996f9bc515373f68cdb73230a9acb1f68bde (patch) | |
| tree | 17da59ff248012eb391faa706bdf7e2be7f44a30 /lib | |
| parent | ebbae4fa0a936f6a4446bc7b4e165ff969d29fd0 (diff) | |
| download | sqlalchemy-4c6c996f9bc515373f68cdb73230a9acb1f68bde.tar.gz | |
- add an example illustrating attribute event reception.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/orm/attributes.py | 5 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/interfaces.py | 13 |
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 2d7c726a1..e67026eea 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -1545,7 +1545,10 @@ class InstrumentationRegistry(object): def state_of(self, instance): if instance is None: raise AttributeError("None has no persistent state.") - return self.state_finders[instance.__class__](instance) + try: + return self.state_finders[instance.__class__](instance) + except KeyError: + raise AttributeError("%r is not instrumented" % instance.__class__) def state_or_default(self, instance, default=None): if instance is None: diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index ff15062aa..6dd2225c8 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -702,17 +702,20 @@ class PropertyOption(MapperOption): return l class AttributeExtension(object): - """An abstract class which specifies `append`, `delete`, and `set` - event handlers to be attached to an object property. + """An event handler for individual attribute change events. + + AttributeExtension is assembled within the descriptors associated + with a mapped class. + """ - def append(self, obj, child, initiator): + def append(self, state, value, initiator): pass - def remove(self, obj, child, initiator): + def remove(self, state, value, initiator): pass - def set(self, obj, child, oldchild, initiator): + def set(self, state, value, oldvalue, initiator): pass |
