- session.merge() propigates given entity_name to locate that mapper if the given object
is transient (and therefore has no entity_name)
- some fixes to MockEngine which still is mostly useless for most cases.
- unitofwork test used incorrect session.delete() signature
engine = property(lambda s: s)
dialect = property(lambda s:s._dialect)
- def contextual_connect(self):
+ def contextual_connect(self, **kwargs):
return self
+ def compiler(self, statement, parameters, **kwargs):
+ return self._dialect.compiler(statement, parameters, engine=self, **kwargs)
+
def create(self, entity, **kwargs):
kwargs['checkfirst'] = False
entity.accept_visitor(self.dialect.schemagenerator(self, **kwargs))
return hasattr(object, '_entity_name')
-def object_mapper(object, raiseerror=True):
+def object_mapper(object, entity_name=None, raiseerror=True):
"""Given an object, return the primary Mapper associated with the object instance.
object
The object instance.
+ entity_name
+ Entity name of the mapper to retrieve, if the given instance is
+ transient. Otherwise uses the entity name already associated
+ with the instance.
+
raiseerror
Defaults to True: raise an ``InvalidRequestError`` if no mapper can
be located. If False, return None.
"""
try:
- mapper = mapper_registry[ClassKey(object.__class__, getattr(object, '_entity_name', None))]
+ mapper = mapper_registry[ClassKey(object.__class__, getattr(object, '_entity_name', entity_name))]
except (KeyError, AttributeError):
if raiseerror:
- raise exceptions.InvalidRequestError("Class '%s' entity name '%s' has no mapper associated with it" % (object.__class__.__name__, getattr(object, '_entity_name', None)))
+ raise exceptions.InvalidRequestError("Class '%s' entity name '%s' has no mapper associated with it" % (object.__class__.__name__, getattr(object, '_entity_name', entity_name)))
else:
return None
return mapper.compile()
else:
self._update_impl(object, entity_name=entity_name)
- def delete(self, object, entity_name=None):
+ def delete(self, object):
"""Mark the given instance as deleted.
The delete operation occurs upon ``flush()``.
for c in [object] + list(_object_mapper(object).cascade_iterator('delete', object)):
self.uow.register_deleted(c)
- def merge(self, object, entity_name=None, _recursive=None):
+ def merge(self, object,entity_name=None, _recursive=None):
"""Copy the state of the given `object` onto the persistent
object with the same identifier.
if _recursive is None:
_recursive = util.Set()
- mapper = _object_mapper(object)
+ mapper = _object_mapper(object, entity_name=entity_name)
key = getattr(object, '_instance_key', None)
if key is None:
merged = mapper._create_instance(self)
f1_s.value='f1rev4'
s2.flush()
- s.delete(f1, f2)
+ s.delete(f1)
+ s.delete(f2)
success = False
try:
s.flush()