def process_record(self, new, old=None): """Additional collection schema validation from bucket, if any.""" new = super().process_record(new, old) # Remove internal and auto-assigned fields. internal_fields = (self.model.id_field, self.model.modified_field, self.model.permissions_field) validate_from_bucket_schema_or_400(new, resource_name="collection", request=self.request, ignore_fields=internal_fields) return new
def process_object(self, new, old=None): """Validate records against collection or bucket schema, if any.""" new = super().process_object(new, old) # Is schema validation enabled? settings = self.request.registry.settings schema_validation = "experimental_collection_schema_validation" if not asbool(settings.get(schema_validation)): return new # Remove internal and auto-assigned fields from schemas and record. ignored_fields = ( self.model.modified_field, self.schema_field, self.model.permissions_field, ) # The schema defined on the collection will be validated first. if "schema" in self._collection: schema = self._collection["schema"] try: validate_schema(new, schema, ignore_fields=ignored_fields, id_field=self.model.id_field) except ValidationError as e: raise_invalid(self.request, name=e.field, description=e.message) except RefResolutionError as e: raise_invalid(self.request, name="schema", description=str(e)) # Assign the schema version to the record. schema_timestamp = self._collection[self.model.modified_field] new[self.schema_field] = schema_timestamp # Validate also from the record:schema field defined on the bucket. validate_from_bucket_schema_or_400( new, resource_name="record", request=self.request, ignore_fields=ignored_fields, id_field=self.model.id_field, ) return new
def process_record(self, new, old=None): """Validate records against collection or bucket schema, if any.""" new = super().process_record(new, old) # Is schema validation enabled? settings = self.request.registry.settings schema_validation = "experimental_collection_schema_validation" if not asbool(settings.get(schema_validation)): return new # Remove internal and auto-assigned fields from schemas and record. internal_fields = ( self.model.id_field, self.model.modified_field, self.schema_field, self.model.permissions_field, ) # The schema defined on the collection will be validated first. if "schema" in self._collection: schema = self._collection["schema"] try: validate_schema(new, schema, ignore_fields=internal_fields) except ValidationError as e: raise_invalid(self.request, name=e.field, description=e.message) except RefResolutionError as e: raise_invalid(self.request, name="schema", description=str(e)) # Assign the schema version to the record. schema_timestamp = self._collection[self.model.modified_field] new[self.schema_field] = schema_timestamp # Validate also from the record:schema field defined on the bucket. validate_from_bucket_schema_or_400( new, resource_name="record", request=self.request, ignore_fields=internal_fields ) return new