def test_serialize_path(self): users, addresses = (self.tables.users, self.tables.addresses) umapper = mapper(User, users, properties={ 'addresses':relationship(Address, backref="user") }) amapper = mapper(Address, addresses) # this is a "relationship" path with mapper, key, mapper, key p1 = (umapper, 'addresses', amapper, 'email_address') eq_( interfaces.deserialize_path(interfaces.serialize_path(p1)), p1 ) # this is a "mapper" path with mapper, key, mapper, no key # at the end. p2 = (umapper, 'addresses', amapper, ) eq_( interfaces.deserialize_path(interfaces.serialize_path(p2)), p2 ) # test a blank path p3 = () eq_( interfaces.deserialize_path(interfaces.serialize_path(p3)), p3 )
def __setstate__(self, state): self.obj = weakref.ref(state['instance'], self._cleanup) self.class_ = state['instance'].__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_) elif manager.is_mapped and not manager.mapper.compiled: manager.mapper.compile() self.committed_state = state.get('committed_state', {}) self.pending = state.get('pending', {}) self.parents = state.get('parents', {}) self.modified = state.get('modified', False) self.expired = state.get('expired', False) self.callables = state.get('callables', {}) if self.modified: self._strong_obj = state['instance'] self.__dict__.update([ (k, state[k]) for k in ( 'key', 'load_options', 'mutable_dict' ) if k in state ]) if 'load_path' in state: self.load_path = interfaces.deserialize_path(state['load_path'])
def __setstate__(self, state): self.obj = weakref.ref(state['instance'], self._cleanup) self.class_ = state['instance'].__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_) elif manager.is_mapped and not manager.mapper.compiled: manager.mapper.compile() self.committed_state = state.get('committed_state', {}) self.pending = state.get('pending', {}) self.parents = state.get('parents', {}) self.modified = state.get('modified', False) self.expired = state.get('expired', False) self.callables = state.get('callables', {}) if self.modified: self._strong_obj = state['instance'] self.__dict__.update([(k, state[k]) for k in ('key', 'load_options', 'mutable_dict') if k in state]) if 'load_path' in state: self.load_path = interfaces.deserialize_path(state['load_path'])
def __setstate__(self, state): self.obj = weakref.ref(state["instance"], self._cleanup) self.class_ = state["instance"].__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_, ) elif manager.mapper and not manager.mapper.compiled: manager.mapper.compile() self.committed_state = state.get("committed_state", {}) self.pending = state.get("pending", {}) self.parents = state.get("parents", {}) self.modified = state.get("modified", False) self.expired = state.get("expired", False) self.callables = state.get("callables", {}) if self.modified: self._strong_obj = state["instance"] self.__dict__.update([(k, state[k]) for k in ("key", "load_options", "mutable_dict") if k in state]) if "load_path" in state: self.load_path = interfaces.deserialize_path(state["load_path"])
def __setstate__(self, state): if state["instance"] is not None: self.obj = weakref.ref(state["instance"]) self.class_ = state["class_"] self.load_options = state["load_options"] self.load_path = state["load_path"] self.manager = instrumentation.manager_of_class(self.class_) if "load_path" in state: self.load_path = interfaces.deserialize_path(state["load_path"])
def __setstate__(self, state): from sqlalchemy.orm import instrumentation inst = state['instance'] if inst is not None: self.obj = weakref.ref(inst, self._cleanup) self.class_ = inst.__class__ else: # None being possible here generally new as of 0.7.4 # due to storage of state in "parents". "class_" # also new. self.obj = None self.class_ = state['class_'] self.manager = manager = instrumentation.manager_of_class(self.class_) if manager is None: raise orm_exc.UnmappedInstanceError( inst, "Cannot deserialize object of type %r - no mapper() has" " been configured for this class within the current Python process!" % self.class_) elif manager.is_mapped and not manager.mapper.configured: mapperlib.configure_mappers() self.committed_state = state.get('committed_state', {}) self.pending = state.get('pending', {}) self.parents = state.get('parents', {}) self.modified = state.get('modified', False) self.expired = state.get('expired', False) self.callables = state.get('callables', {}) if self.modified: self._strong_obj = inst self.__dict__.update([ (k, state[k]) for k in ( 'key', 'load_options', 'mutable_dict' ) if k in state ]) if 'load_path' in state: self.load_path = interfaces.deserialize_path(state['load_path']) # setup _sa_instance_state ahead of time so that # unpickle events can access the object normally. # see [ticket:2362] manager.setup_instance(inst, self) manager.dispatch.unpickle(self, state)
def __setstate__(self, state): self.obj = weakref.ref(state['instance']) self.class_ = state['instance'].__class__ self.manager = manager_of_class(self.class_) self.committed_state = state.get('committed_state', {}) self.pending = state.get('pending', {}) self.parents = state.get('parents', {}) self.modified = state.get('modified', False) self.expired = state.get('expired', False) self.callables = state.get('callables', {}) self.__dict__.update((k, state[k]) for k in ('key', 'load_options', 'expired_attributes', 'mutable_dict') if k in state) if 'load_path' in state: self.load_path = interfaces.deserialize_path(state['load_path'])
def __setstate__(self, state): self.obj = weakref.ref(state['instance']) self.class_ = state['instance'].__class__ self.manager = manager_of_class(self.class_) self.committed_state = state.get('committed_state', {}) self.pending = state.get('pending', {}) self.parents = state.get('parents', {}) self.modified = state.get('modified', False) self.expired = state.get('expired', False) self.callables = state.get('callables', {}) self.__dict__.update( (k, state[k]) for k in ( 'key', 'load_options', 'expired_attributes', 'mutable_dict' ) if k in state ) if 'load_path' in state: self.load_path = interfaces.deserialize_path(state['load_path'])
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.committed_state = state.get("committed_state", {}) self.pending = state.get("pending", {}) self.parents = state.get("parents", {}) self.modified = state.get("modified", False) self.expired = state.get("expired", False) self.callables = state.get("callables", {}) if self.modified: self._strong_obj = state["instance"] self.__dict__.update( (k, state[k]) for k in ("key", "load_options", "expired_attributes", "mutable_dict") if k in state ) if "load_path" in state: self.load_path = interfaces.deserialize_path(state["load_path"])
def __setstate__(self, state): from sqlalchemy.orm import instrumentation inst = state["instance"] if inst is not None: self.obj = weakref.ref(inst, self._cleanup) self.class_ = inst.__class__ else: # None being possible here generally new as of 0.7.4 # due to storage of state in "parents". "class_" # also new. self.obj = None self.class_ = state["class_"] self.manager = manager = instrumentation.manager_of_class(self.class_) if manager is None: raise orm_exc.UnmappedInstanceError( inst, "Cannot deserialize object of type %r - no mapper() has" " been configured for this class within the current Python process!" % self.class_, ) elif manager.is_mapped and not manager.mapper.configured: mapperlib.configure_mappers() self.committed_state = state.get("committed_state", {}) self.pending = state.get("pending", {}) self.parents = state.get("parents", {}) self.modified = state.get("modified", False) self.expired = state.get("expired", False) self.callables = state.get("callables", {}) if self.modified: self._strong_obj = inst self.__dict__.update([(k, state[k]) for k in ("key", "load_options", "mutable_dict") if k in state]) if "load_path" in state: self.load_path = interfaces.deserialize_path(state["load_path"]) manager.dispatch.unpickle(self, state)
def __setstate__(self, state): self.state, self.key, self.options, path = state self.path = deserialize_path(path)
def __setstate__(self, state): self.instance = state['instance'] self.key = state['key'] self.options = state['options'] self.path = deserialize_path(state['path'])
def __setstate__(self, state): self.instance = state['instance'] self.key = state['key'] self.options= state['options'] self.path = deserialize_path(state['path'])