def save(self, render_name=False, *args, **kwargs): # pylint: disable=keyword-arg-before-vararg """Save the data model.""" if self.name != self._original_name: self.named_by_user = True create = self.pk is None if create: fill_with_defaults(self.input, self.process.input_schema) # pylint: disable=no-member if not self.name: self._render_name() else: self.named_by_user = True self.checksum = get_data_checksum( self.input, self.process.slug, self.process.version) # pylint: disable=no-member elif render_name: self._render_name() self.save_storage(self.output, self.process.output_schema) # pylint: disable=no-member if self.status != Data.STATUS_ERROR: hydrate_size(self) # If only specified fields are updated (e.g. in executor), size needs to be added if 'update_fields' in kwargs: kwargs['update_fields'].append('size') # Input Data objects are validated only upon creation as they can be deleted later. skip_missing_data = not create validate_schema( self.input, self.process.input_schema, skip_missing_data=skip_missing_data # pylint: disable=no-member ) render_descriptor(self) if self.descriptor_schema: try: validate_schema(self.descriptor, self.descriptor_schema.schema) # pylint: disable=no-member self.descriptor_dirty = False except DirtyError: self.descriptor_dirty = True elif self.descriptor and self.descriptor != {}: raise ValueError("`descriptor_schema` must be defined if `descriptor` is given") if self.status != Data.STATUS_ERROR: output_schema = self.process.output_schema # pylint: disable=no-member if self.status == Data.STATUS_DONE: validate_schema( self.output, output_schema, data_location=self.location, skip_missing_data=True ) else: validate_schema( self.output, output_schema, data_location=self.location, test_required=False ) with transaction.atomic(): self._perform_save(*args, **kwargs)
def save(self, render_name=False, *args, **kwargs): """Save the data model.""" if self.name != self._original_name: self.named_by_user = True try: jsonschema.validate( self.process_resources, validation_schema("process_resources") ) except jsonschema.exceptions.ValidationError as exception: # Re-raise as Django ValidationError raise ValidationError(exception.message) create = self.pk is None if create: fill_with_defaults(self.input, self.process.input_schema) if not self.name: self._render_name() else: self.named_by_user = True self.checksum = get_data_checksum( self.input, self.process.slug, self.process.version ) validate_schema(self.input, self.process.input_schema) hydrate_size(self) # If only specified fields are updated (e.g. in executor), size needs to be added if "update_fields" in kwargs: kwargs["update_fields"].append("size") elif render_name: self._render_name() render_descriptor(self) if self.descriptor_schema: try: validate_schema(self.descriptor, self.descriptor_schema.schema) self.descriptor_dirty = False except DirtyError: self.descriptor_dirty = True elif self.descriptor and self.descriptor != {}: raise ValueError( "`descriptor_schema` must be defined if `descriptor` is given" ) with transaction.atomic(): self._perform_save(*args, **kwargs) self._original_output = self.output
def perform_get_or_create(self, request, *args, **kwargs): """Perform "get_or_create" - return existing object if found.""" serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) process = serializer.validated_data.get('process') process_input = request.data.get('input', {}) fill_with_defaults(process_input, process.input_schema) checksum = get_data_checksum(process_input, process.slug, process.version) data_qs = Data.objects.filter( checksum=checksum, process__persistence__in=[Process.PERSISTENCE_CACHED, Process.PERSISTENCE_TEMP], ) data_qs = get_objects_for_user(request.user, 'view_data', data_qs) if data_qs.exists(): data = data_qs.order_by('created').last() serializer = self.get_serializer(data) return Response(serializer.data)
def save(self, render_name=False, *args, **kwargs): # pylint: disable=keyword-arg-before-vararg """Save the data model.""" # Generate the descriptor if one is not already set. if self.name != self._original_name: self.named_by_user = True create = self.pk is None if create: fill_with_defaults(self.input, self.process.input_schema) # pylint: disable=no-member if not self.name: self._render_name() else: self.named_by_user = True self.checksum = get_data_checksum(self.input, self.process.slug, self.process.version) # pylint: disable=no-member elif render_name: self._render_name() self.save_storage(self.output, self.process.output_schema) # pylint: disable=no-member if self.status != Data.STATUS_ERROR: hydrate_size(self) # If only specified fields are updated (e.g. in executor), size needs to be added if 'update_fields' in kwargs: kwargs['update_fields'].append('size') # Input Data objects are validated only upon creation as they can be deleted later. skip_missing_data = not create validate_schema( self.input, self.process.input_schema, skip_missing_data=skip_missing_data # pylint: disable=no-member ) render_descriptor(self) if self.descriptor_schema: try: validate_schema(self.descriptor, self.descriptor_schema.schema) # pylint: disable=no-member self.descriptor_dirty = False except DirtyError: self.descriptor_dirty = True elif self.descriptor and self.descriptor != {}: raise ValueError( "`descriptor_schema` must be defined if `descriptor` is given") if self.status != Data.STATUS_ERROR: path_prefix = os.path.join(settings.FLOW_EXECUTOR['DATA_DIR'], str(self.pk)) output_schema = self.process.output_schema # pylint: disable=no-member if self.status == Data.STATUS_DONE: validate_schema(self.output, output_schema, path_prefix=path_prefix) else: validate_schema(self.output, output_schema, path_prefix=path_prefix, test_required=False) with transaction.atomic(): super().save(*args, **kwargs) # We can only save dependencies after the data object has been saved. This # is why a transaction block is needed and the save method must be called first. if create: self.save_dependencies(self.input, self.process.input_schema) # pylint: disable=no-member self.create_entity()
def save(self, render_name=False, *args, **kwargs): # pylint: disable=keyword-arg-before-vararg """Save the data model.""" if self.name != self._original_name: self.named_by_user = True create = self.pk is None if create: fill_with_defaults(self.input, self.process.input_schema) # pylint: disable=no-member if not self.name: self._render_name() else: self.named_by_user = True self.checksum = get_data_checksum( self.input, self.process.slug, self.process.version) # pylint: disable=no-member elif render_name: self._render_name() self.save_storage(self.output, self.process.output_schema) # pylint: disable=no-member if self.status != Data.STATUS_ERROR: hydrate_size(self) # If only specified fields are updated (e.g. in executor), size needs to be added if 'update_fields' in kwargs: kwargs['update_fields'].append('size') # Input Data objects are validated only upon creation as they can be deleted later. skip_missing_data = not create validate_schema( self.input, self.process.input_schema, skip_missing_data=skip_missing_data # pylint: disable=no-member ) render_descriptor(self) if self.descriptor_schema: try: validate_schema(self.descriptor, self.descriptor_schema.schema) # pylint: disable=no-member self.descriptor_dirty = False except DirtyError: self.descriptor_dirty = True elif self.descriptor and self.descriptor != {}: raise ValueError("`descriptor_schema` must be defined if `descriptor` is given") if self.status != Data.STATUS_ERROR: output_schema = self.process.output_schema # pylint: disable=no-member if self.status == Data.STATUS_DONE: validate_schema( self.output, output_schema, data_location=self.location, skip_missing_data=True ) else: validate_schema( self.output, output_schema, data_location=self.location, test_required=False ) with transaction.atomic(): self._perform_save(*args, **kwargs) # We can only save dependencies after the data object has been saved. This # is why a transaction block is needed and the save method must be called first. if create: self.save_dependencies(self.input, self.process.input_schema) # pylint: disable=no-member self.create_entity()