ordering among a polymorphic chain of instances. Therefore
_save_obj is typically called only on a *base mapper*, or a
mapper which does not inherit from any other mapper.
+
"""
-
if self._should_log_debug:
self.__log_debug("_save_obj() start, " + (single and "non-batched" or "batched"))
self.__log_debug("detected row switch for identity %s. will update %s, remove %s from transaction" % (instance_key, state_str(state), state_str(existing)))
uowtransaction.set_row_switch(existing)
- inserted_objects = set()
- updated_objects = set()
-
table_to_mapper = {}
for mapper in self.base_mapper.polymorphic_iterator():
for t in mapper.tables:
self.__log_debug("_save_obj() table '%s' instance %s identity %s" % (table.name, state_str(state), str(instance_key)))
isinsert = not instance_key in uowtransaction.session.identity_map and not postupdate and not has_identity
+
params = {}
value_params = {}
hasdata = False
statement = table.update(clause)
rows = 0
- for rec in update:
- (state, params, mapper, connection, value_params) = rec
+ for state, params, mapper, connection, value_params in update:
c = connection.execute(statement.values(value_params), params)
mapper._postfetch(uowtransaction, connection, table, state, c, c.last_updated_params(), value_params)
- # testlib.pragma exempt:__hash__
- updated_objects.add((state, connection))
rows += c.rowcount
if c.supports_sane_rowcount() and rows != len(update):
if insert:
statement = table.insert()
- for rec in insert:
- (state, params, mapper, connection, value_params) = rec
+ for state, params, mapper, connection, value_params in insert:
c = connection.execute(statement.values(value_params), params)
primary_key = c.last_inserted_ids()
if m.__inherits_equated_pairs:
sync.populate(state, m, state, m, m.__inherits_equated_pairs)
- # testlib.pragma exempt:__hash__
- inserted_objects.add((state, connection))
-
if not postupdate:
for state, mapper, connection, has_identity in tups:
# if join conditions were not specified, figure them out based on foreign keys
def _search_for_join(mapper, table):
- """find a join between the given mapper's mapped table and the given table.
- will try the mapper's local table first for more specificity, then if not
- found will try the more general mapped table, which in the case of inheritance
- is a join."""
+ # find a join between the given mapper's mapped table and the given table.
+ # will try the mapper's local table first for more specificity, then if not
+ # found will try the more general mapped table, which in the case of inheritance
+ # is a join.
try:
return sql.join(mapper.local_table, table)
except sa_exc.ArgumentError, e:
if self.primaryjoin is None:
self.primaryjoin = _search_for_join(self.parent, self.target).onclause
except sa_exc.ArgumentError, e:
- raise sa_exc.ArgumentError("Could not determine join condition between parent/child tables on relation %s. "
- "Specify a 'primaryjoin' expression. If this is a many-to-many relation, 'secondaryjoin' is needed as well." % (self))
+ raise sa_exc.ArgumentError("Could not determine join condition between "
+ "parent/child tables on relation %s. "
+ "Specify a 'primaryjoin' expression. If this is a "
+ "many-to-many relation, 'secondaryjoin' is needed as well." % (self))
def _col_is_part_of_mappings(self, column):
if self.secondary is None:
if not eq_pairs:
if not self.viewonly and criterion_as_pairs(self.primaryjoin, consider_as_foreign_keys=self._foreign_keys, any_operator=True):
- raise sa_exc.ArgumentError("Could not locate any equated, locally mapped column pairs for primaryjoin condition '%s' on relation %s. "
- "For more relaxed rules on join conditions, the relation may be marked as viewonly=True." % (self.primaryjoin, self)
+ raise sa_exc.ArgumentError("Could not locate any equated, locally "
+ "mapped column pairs for primaryjoin condition '%s' on relation %s. "
+ "For more relaxed rules on join conditions, the relation may be "
+ "marked as viewonly=True." % (self.primaryjoin, self)
)
else:
if self._foreign_keys:
- raise sa_exc.ArgumentError("Could not determine relation direction for primaryjoin condition '%s', on relation %s. "
- "Are the columns in 'foreign_keys' present within the given join condition ?" % (self.primaryjoin, self))
+ raise sa_exc.ArgumentError("Could not determine relation direction for "
+ "primaryjoin condition '%s', on relation %s. "
+ "Are the columns in 'foreign_keys' present within the given "
+ "join condition ?" % (self.primaryjoin, self))
else:
- raise sa_exc.ArgumentError("Could not determine relation direction for primaryjoin condition '%s', on relation %s. "
- "Specify the 'foreign_keys' argument to indicate which columns on the relation are foreign." % (self.primaryjoin, self))
+ raise sa_exc.ArgumentError("Could not determine relation direction for "
+ "primaryjoin condition '%s', on relation %s. "
+ "Specify the 'foreign_keys' argument to indicate which columns "
+ "on the relation are foreign." % (self.primaryjoin, self))
self.synchronize_pairs = eq_pairs
if not sq_pairs:
if not self.viewonly and criterion_as_pairs(self.secondaryjoin, consider_as_foreign_keys=self._foreign_keys, any_operator=True):
- raise sa_exc.ArgumentError("Could not locate any equated, locally mapped column pairs for secondaryjoin condition '%s' on relation %s. "
- "For more relaxed rules on join conditions, the relation may be marked as viewonly=True." % (self.secondaryjoin, self)
+ raise sa_exc.ArgumentError("Could not locate any equated, locally mapped "
+ "column pairs for secondaryjoin condition '%s' on relation %s. "
+ "For more relaxed rules on join conditions, the "
+ "relation may be marked as viewonly=True." % (self.secondaryjoin, self)
)
else:
- raise sa_exc.ArgumentError("Could not determine relation direction for secondaryjoin condition '%s', on relation %s. "
- "Specify the foreign_keys argument to indicate which columns on the relation are foreign." % (self.secondaryjoin, self))
+ raise sa_exc.ArgumentError("Could not determine relation direction "
+ "for secondaryjoin condition '%s', on relation %s. "
+ "Specify the foreign_keys argument to indicate which "
+ "columns on the relation are foreign." % (self.secondaryjoin, self))
self.secondary_synchronize_pairs = sq_pairs
else:
for l, r in self.local_remote_pairs:
if self.direction is ONETOMANY and not self._col_is_part_of_mappings(l):
- raise sa_exc.ArgumentError("Local column '%s' is not part of mapping %s. Specify remote_side argument to indicate which column lazy join condition should compare against." % (l, self.parent))
+ raise sa_exc.ArgumentError("Local column '%s' is not part of mapping %s. "
+ "Specify remote_side argument to indicate which column "
+ "lazy join condition should compare against." % (l, self.parent))
elif self.direction is MANYTOONE and not self._col_is_part_of_mappings(r):
- raise sa_exc.ArgumentError("Remote column '%s' is not part of mapping %s. Specify remote_side argument to indicate which column lazy join condition should bind." % (r, self.mapper))
+ raise sa_exc.ArgumentError("Remote column '%s' is not part of mapping %s. "
+ "Specify remote_side argument to indicate which column lazy "
+ "join condition should bind." % (r, self.mapper))
self.local_side, self.remote_side = [util.OrderedSet(x) for x in zip(*list(self.local_remote_pairs))]
if self.backref is not None:
self.backref.compile(self)
elif not mapper.class_mapper(self.parent.class_, compile=False)._get_property(self.key, raiseerr=False):
- raise sa_exc.ArgumentError("Attempting to assign a new relation '%s' to a non-primary mapper on class '%s'. New relations can only be added to the primary mapper, i.e. the very first mapper created for class '%s' " % (self.key, self.parent.class_.__name__, self.parent.class_.__name__))
+ raise sa_exc.ArgumentError("Attempting to assign a new relation '%s' to "
+ "a non-primary mapper on class '%s'. New relations can only be "
+ "added to the primary mapper, i.e. the very first "
+ "mapper created for class '%s' " % (self.key, self.parent.class_.__name__, self.parent.class_.__name__))
super(PropertyLoader, self).do_init()
else:
target_adapter = None
- self.__join_cache[key] = ret = (primaryjoin, secondaryjoin, (source_selectable or self.parent.local_table), (dest_selectable or self.mapper.local_table), secondary, target_adapter)
+ self.__join_cache[key] = ret = (primaryjoin, secondaryjoin,
+ (source_selectable or self.parent.local_table),
+ (dest_selectable or self.mapper.local_table), secondary, target_adapter)
return ret
def _get_join(self, parent, primary=True, secondary=True, polymorphic_parent=True):
else:
raise AssertionError("illegal condition")
-
def register_dependencies(self, uowcommit):
if not self.viewonly:
self._dependency_processor.register_dependencies(uowcommit)
mapper._get_property(self.key)._reverse_property = prop
else:
- raise sa_exc.ArgumentError("Error creating backref '%s' on relation '%s': property of that name exists on mapper '%s'" % (self.key, prop, mapper))
+ raise sa_exc.ArgumentError("Error creating backref '%s' on relation '%s': "
+ "property of that name exists on mapper '%s'" % (self.key, prop, mapper))
mapper.ColumnProperty = ColumnProperty
mapper.SynonymProperty = SynonymProperty
return newvalue
def register_attribute(class_, key, *args, **kwargs):
- """overrides attributes.register_attribute() to add UOW event handlers
- to new InstrumentedAttributes.
+ """Register an attribute with the attributes module.
+
+ Overrides attributes.register_attribute() to add
+ unitofwork-specific event handlers.
+
"""
-
useobject = kwargs.get('useobject', False)
if useobject:
# for object-holding attributes, instrument UOWEventHandler
this indicates that an INSERT statement elsewhere corresponds to this DELETE;
the INSERT is converted to an UPDATE and the DELETE does not occur.
+
"""
mapper = _state_mapper(state)
task = self.get_task_by_mapper(mapper)
Will create a new UOWTask, including a UOWTask corresponding to the
"base" inherited mapper, if needed, unless the dontcreate flag is True.
+
"""
try:
return self.tasks[mapper]
Called by ``mapper.PropertyLoader`` to register the objects
handled by one mapper being dependent on the objects handled
by another.
- """
+ """
# correct for primary mapper
# also convert to the "base mapper", the parentmost task at the top of an inheritance chain
# dependency sorting is done via non-inheriting mappers only, dependencies between mappers
the two given mappers.
"""
-
# correct for primary mapper
mapper = mapper.primary_mapper()
mapperfrom = mapperfrom.primary_mapper()
def execute_save_steps(self, trans, task):
self.save_objects(trans, task)
self.execute_cyclical_dependencies(trans, task, False)
- self.execute_dependencies(trans, task, False)
- self.execute_dependencies(trans, task, True)
+ self.execute_dependencies(trans, task)
def execute_delete_steps(self, trans, task):
self.execute_cyclical_dependencies(trans, task, True)
self.delete_objects(trans, task)
- def execute_dependencies(self, trans, task, isdelete=None):
- if isdelete is not True:
- for dep in task.polymorphic_dependencies:
- self.execute_dependency(trans, dep, False)
- if isdelete is not False:
- for dep in reversed(list(task.polymorphic_dependencies)):
- self.execute_dependency(trans, dep, True)
+ def execute_dependencies(self, trans, task):
+ polymorphic_dependencies = list(task.polymorphic_dependencies)
+ for dep in polymorphic_dependencies:
+ self.execute_dependency(trans, dep, False)
+ for dep in reversed(polymorphic_dependencies):
+ self.execute_dependency(trans, dep, True)
def execute_cyclical_dependencies(self, trans, task, isdelete):
for dep in task.polymorphic_cyclical_dependencies: