Exemple #1
0
            def setter(self, value, name=name, field=field):
                attrname = _get_attrname(name)
                field_value = field.coerce(self, name, value)
                if field.read_only and hasattr(self, attrname):
                    # Note(yjiang5): _from_db_object() may iterate
                    # every field and write, no exception in such situation.
                    if getattr(self, attrname) != field_value:
                        raise exception.ReadOnlyFieldError(field=name)
                    else:
                        return

                self._changed_fields.add(name)
                # TODO(daidv): _obj_original_values shoud be removed
                # after OVO migration completed.
                if (self.obj_attr_is_set(name)
                        and value != getattr(self, name) and name not in list(
                            six.iterkeys(self._obj_original_values))):  # noqa
                    self._obj_original_values[name] = getattr(self, name)
                try:
                    return setattr(self, attrname, field_value)
                except Exception:
                    with excutils.save_and_reraise_exception():
                        LOG.exception(
                            'Error setting %{obj_name}s.%{field_name}s', {
                                "obj_name": self.obj_name(),
                                "field_name": name
                            })
        def setter(self, value, name=name, field=field):
            attrname = _get_attrname(name)
            field_value = field.coerce(self, name, value)
            if field.read_only and hasattr(self, attrname):
                # Note(yjiang5): _from_db_object() may iterate
                # every field and write, no exception in such situation.
                if getattr(self, attrname) != field_value:
                    raise exception.ReadOnlyFieldError(field=name)
                else:
                    return

            self._changed_fields.add(name)
            try:
                return setattr(self, attrname, field_value)
            except Exception:
                with excutils.save_and_reraise_exception():
                    attr = "%s.%s" % (self.obj_name(), name)
                    LOG.exception(_LE('Error setting %(attr)s'),
                                  {'attr': attr})