diff --git a/src/backend/InvenTree/common/models.py b/src/backend/InvenTree/common/models.py index 3a5a7ad7c2..645abd28e6 100644 --- a/src/backend/InvenTree/common/models.py +++ b/src/backend/InvenTree/common/models.py @@ -3241,6 +3241,6 @@ class Attachment(InvenTree.models.MetadataMixin, InvenTree.models.InvenTreeModel ) if not issubclass(model_class, InvenTreeAttachmentMixin): - raise ValueError(_('Invalid model type specified for attachment')) + raise ValidationError(_('Invalid model type specified for attachment')) return model_class.check_attachment_permission(permission, user) diff --git a/src/backend/InvenTree/common/validators.py b/src/backend/InvenTree/common/validators.py index 5edd4a0f9a..a806e6cc0d 100644 --- a/src/backend/InvenTree/common/validators.py +++ b/src/backend/InvenTree/common/validators.py @@ -29,11 +29,14 @@ def attachment_model_options(): def attachment_model_class_from_label(label: str): """Return the model class for the given label.""" + if not label: + raise ValidationError(_('No attachment model type provided')) + for model in attachment_model_types(): if model.__name__.lower() == label.lower(): return model - raise ValueError(f'Invalid attachment model label: {label}') + raise ValidationError(_('Invalid attachment model type') + f": '{label}'") def validate_attachment_model_type(value):