def create(self, data):
        """ Create object from the given data.

        The given data may or may not have been validated prior to calling
        this function. This function will try its best in creating the object.
        If the resulting object cannot be produced, raises ``ValidationError``.

        The spec can affect how individual fields will be created by
        implementing ``clean()`` for the fields needing customization.

        :param data: the data as a dictionary.
        :return: instance of ``klass`` or dictionary.
        :raises: ``ValidationError`` if factory is unable to create object.
        """

        # todo: copy-paste code from representation.validate -> refactor

        if data is None:
            return None

        prototype = {}
        errors = {}

        # create and populate the prototype
        for field_name, field_spec in self.spec.fields.items():
            try:
                value = self._create_value(data, field_name, self.spec)
            except ValidationError, e:
                if field_name not in self.default_create_values:
                    if hasattr(e, 'message_dict'):
                        # prefix error keys with top level field name
                        errors.update(dict(zip(
                            [field_name + '.' + key for key in e.message_dict.keys()],
                            e.message_dict.values())))
                    else:
                        errors[field_name] = e.messages
            else:
                key_name = self.property_name_map[field_name]
                prototype[key_name] = value

        # check extra fields
        if self.prevent_extra_fields:
            extras = set(self.property_name_map.keys()) - set(data.keys())
            if extras:
                errors[', '.join(extras)] = ['field(s) not allowed']

        # if errors, raise ValidationError
        if errors:
            raise ValidationError(errors)

        # return dict or object based on the prototype
        _data = deepcopy(self.default_create_values)
        _data.update(prototype)
        if self.klass:
            instance = self.klass()
            instance.__dict__.update(prototype)
            return instance
        else:
            return prototype
dataset/ETHPy150Open wuher/devil/devil/fields/factory.py/Factory.create/swapped operands of `-`