except KeyError:
prop = self.__props.get(column.key, None)
if prop:
- raise exceptions.InvalidRequestError("Column '%s.%s' is not available, due to conflicting property '%s':%s" % (column.table.name, column.name, column.key, repr(prop)))
+ raise exceptions.UnmappedColumnError("Column '%s.%s' is not available, due to conflicting property '%s':%s" % (column.table.name, column.name, column.key, repr(prop)))
else:
- raise exceptions.InvalidRequestError("No column %s.%s is configured on mapper %s..." % (column.table.name, column.name, str(self)))
+ raise exceptions.UnmappedColumnError("No column %s.%s is configured on mapper %s..." % (column.table.name, column.name, str(self)))
def _get_state_attr_by_column(self, state, column):
return self._get_col_to_prop(column).getattr(state, column)
self.issecondary = issecondary
self.dest_mapper = dest_mapper
self.dest_column = dest_column
-
+
#print "SyncRule", source_mapper, source_column, dest_column, dest_mapper
def dest_primary_key(self):
self._dest_primary_key = self.dest_mapper is not None and self.dest_column in self.dest_mapper._pks_by_table[self.dest_column.table] and not self.dest_mapper.allow_null_pks
return self._dest_primary_key
+ def _raise_col_to_prop(self, isdest):
+ if isdest:
+ raise exceptions.UnmappedColumnError("Can't execute sync rule for destination column '%s'; mapper '%s' does not map this column. Try using an explicit `foreign_keys` collection which does not include this column (or use a viewonly=True relation)." % (self.dest_column, self.dest_mapper))
+ else:
+ raise exceptions.UnmappedColumnError("Can't execute sync rule for source column '%s'; mapper '%s' does not map this column. Try using an explicit `foreign_keys` collection which does not include destination column '%s' (or use a viewonly=True relation)." % (self.source_column, self.source_mapper, self.dest_column))
+
def source_changes(self, uowcommit, source):
- prop = self.source_mapper._columntoproperty[self.source_column]
+ try:
+ prop = self.source_mapper._get_col_to_prop(self.source_column)
+ except exceptions.UnmappedColumnError:
+ self._raise_col_to_prop(False)
(added, unchanged, deleted) = uowcommit.get_attribute_history(source, prop.key, passive=True)
return bool(added and deleted)
source = parent
elif self.issecondary is True:
source = child
- oldvalue = self.source_mapper._get_committed_attr_by_column(source.obj(), self.source_column)
- value = self.source_mapper._get_state_attr_by_column(source, self.source_column)
+ try:
+ oldvalue = self.source_mapper._get_committed_attr_by_column(source.obj(), self.source_column)
+ value = self.source_mapper._get_state_attr_by_column(source, self.source_column)
+ except exceptions.UnmappedColumnError:
+ self._raise_col_to_prop(False)
dest[self.dest_column.key] = value
dest[old_prefix + self.dest_column.key] = oldvalue
value = None
clearkeys = True
else:
- value = self.source_mapper._get_state_attr_by_column(source, self.source_column)
+ try:
+ value = self.source_mapper._get_state_attr_by_column(source, self.source_column)
+ except exceptions.UnmappedColumnError:
+ self._raise_col_to_prop(False)
if isinstance(dest, dict):
dest[self.dest_column.key] = value
else:
if logging.is_debug_enabled(self.logger):
self.logger.debug("execute() instances: %s(%s)->%s(%s) ('%s')" % (mapperutil.state_str(source), str(self.source_column), mapperutil.state_str(dest), str(self.dest_column), value))
- self.dest_mapper._set_state_attr_by_column(dest, self.dest_column, value)
+ try:
+ self.dest_mapper._set_state_attr_by_column(dest, self.dest_column, value)
+ except exceptions.UnmappedColumnError:
+ self._raise_col_to_prop(True)
SyncRule.logger = logging.class_logger(SyncRule)