diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-01-17 22:23:54 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-01-17 22:23:54 +0000 |
| commit | e9076d04b0ec82a403a885be7999eab7d346923b (patch) | |
| tree | 4870d4f61a0a8b0125f364b16b1a5ebb24642ffb /lib/sqlalchemy | |
| parent | 8fa55917acbe28d96c83983d2f1b01d51a952d1c (diff) | |
| download | sqlalchemy-e9076d04b0ec82a403a885be7999eab7d346923b.tar.gz | |
- raise error when unpickling non-mapped state, [ticket:1610]
- remove pickle language from regular unmapped class error
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/exc.py | 6 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/state.py | 17 |
2 files changed, 14 insertions, 9 deletions
diff --git a/lib/sqlalchemy/orm/exc.py b/lib/sqlalchemy/orm/exc.py index ccb4feda2..8b52eec8a 100644 --- a/lib/sqlalchemy/orm/exc.py +++ b/lib/sqlalchemy/orm/exc.py @@ -33,10 +33,8 @@ class UnmappedInstanceError(UnmappedError): mapper = sa.orm.class_mapper(type(obj)) name = _safe_cls_name(type(obj)) msg = ("Class %r is mapped, but this instance lacks " - "instrumentation. Possible causes: instance created " - "before sqlalchemy.orm.mapper(%s) was called, or " - "instance was pickled/depickled without instrumentation" - "information." % (name, name)) + "instrumentation. This occurs when the instance is created " + "before sqlalchemy.orm.mapper(%s) was called." % (name, name)) except UnmappedClassError: msg = _default_unmapped(type(obj)) if isinstance(obj, type): diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py index 042f06710..472d2c081 100644 --- a/lib/sqlalchemy/orm/state.py +++ b/lib/sqlalchemy/orm/state.py @@ -1,9 +1,10 @@ from sqlalchemy.util import EMPTY_SET import weakref from sqlalchemy import util -from sqlalchemy.orm.attributes import PASSIVE_NO_RESULT, PASSIVE_OFF, NEVER_SET, NO_VALUE, manager_of_class, ATTR_WAS_SET -from sqlalchemy.orm import attributes -from sqlalchemy.orm import interfaces +from sqlalchemy.orm.attributes import PASSIVE_NO_RESULT, PASSIVE_OFF, \ + NEVER_SET, NO_VALUE, manager_of_class, \ + ATTR_WAS_SET +from sqlalchemy.orm import attributes, exc as orm_exc, interfaces class InstanceState(object): """tracks state information at the instance level.""" @@ -147,8 +148,14 @@ class InstanceState(object): def __setstate__(self, state): self.obj = weakref.ref(state['instance'], self._cleanup) self.class_ = state['instance'].__class__ - self.manager = manager_of_class(self.class_) - + self.manager = manager = manager_of_class(self.class_) + if manager is None: + raise orm_exc.UnmappedInstanceError( + state['instance'], + "Cannot deserialize object of type %r - no mapper() has" + " been configured for this class within the current Python process!" % + self.class_) + self.committed_state = state.get('committed_state', {}) self.pending = state.get('pending', {}) self.parents = state.get('parents', {}) |
