def create(self, validated_data): is_managed = validated_data["is_managed"] content = validated_data.get("content") if content: is_managed = True if is_managed is None else is_managed if is_managed and not content: raise ValidationError( "Managed runs require a content with valid specification") user = validated_data.get("user") if is_managed: try: op_spec = OperationSpecification.read(content) except Exception as e: raise ValidationError(e) return compile_operation_run( project_id=validated_data["project"].id, user_id=user.id if user else None, op_spec=op_spec, name=validated_data.get("name"), description=validated_data.get("description"), tags=validated_data.get("tags"), ) else: return create_run( project_id=validated_data["project"].id, user_id=user.id if user else None, name=validated_data.get("name"), description=validated_data.get("description"), tags=validated_data.get("tags"), )
def create(self, validated_data): is_managed = validated_data["is_managed"] content = validated_data.get("content") meta_info = validated_data.get("meta_info") or {} if content: is_managed = True if is_managed is None else is_managed if is_managed and not content: raise ValidationError( "Managed runs require a content with valid specification" ) project_id = validated_data["project"].id user = validated_data.get("user") name = validated_data.get("name") description = validated_data.get("description") tags = validated_data.get("tags") pending = validated_data.get("pending") # Check the deprecated `is_approved` flag if pending is None: is_approved = validated_data.get("is_approved") if is_approved is False: pending = V1RunPending.UPLOAD if is_managed or content: try: op_spec = OperationSpecification.read(content) except Exception as e: raise ValidationError(e) if op_spec.is_template(): raise ValidationError( "Received a template polyaxonfile, " "Please customize the specification or disable the template." ) try: return compile_operation_run( project_id=project_id, user_id=user.id if user else None, op_spec=op_spec, name=name, description=description, tags=tags, meta_info=meta_info, is_managed=is_managed, pending=pending, supported_kinds=validated_data.get("supported_kinds"), supported_owners=validated_data.get("supported_owners"), ) except (MarshmallowValidationError, PolyaxonException, ValueError) as e: raise ValidationError(e) else: return create_run( project_id=project_id, user_id=user.id if user else None, name=name, description=description, tags=tags, meta_info=meta_info, )
def create(self, validated_data): is_managed = validated_data["is_managed"] content = validated_data.get("content") if content: is_managed = True if is_managed is None else is_managed if is_managed and not content: raise ValidationError( "Managed runs require a content with valid specification" ) project_id = validated_data["project"].id user = validated_data.get("user") name = validated_data.get("name") description = validated_data.get("description") tags = validated_data.get("tags") if is_managed or content: try: op_spec = OperationSpecification.read(content) except Exception as e: raise ValidationError(e) if op_spec.is_template(): raise ValidationError( "Received a template polyaxonfile, " "Please customize the specification or disable the template." ) try: return compile_operation_run( project_id=project_id, user_id=user.id if user else None, op_spec=op_spec, name=name, description=description, tags=tags, is_managed=is_managed, supported_kinds=validated_data.get("supported_kinds"), ) except (PolyaxonException, ValueError) as e: raise ValidationError(e) else: return create_run( project_id=project_id, user_id=user.id if user else None, name=name, description=description, tags=tags, )