Added fields to error messages.
Change-Id: Iad4e95378e6056f01fc52738f453b129ecec7f24
diff --git a/xos/core/models/attic/servicedependency_model.py b/xos/core/models/attic/servicedependency_model.py
index dce32e7..b2d2da6 100644
--- a/xos/core/models/attic/servicedependency_model.py
+++ b/xos/core/models/attic/servicedependency_model.py
@@ -2,10 +2,12 @@
def save(self, *args, **kwargs):
if (not self.subscriber_service):
- raise XOSValidationError("subscriber_service cannot be null")
- if (self.subscriber_tenant or self.subscriber_user):
- raise XOSValidationError(
- "subscriber_tenant and subscriber_user must be null")
+ raise XOSValidationError("subscriber_service cannot be null", {'subscriber service' : 'subscriber_service cannot be null'})
+ if (self.subscriber_tenant):
+ raise XOSValidationError("subscriber_tenant must be null", {'subscriber tenant' : 'subscriber_tenant must be null'})
+ if (self.subscriber_user):
+ raise XOSValidationError("subscriber_user must be null", {'subscriber user' : 'subscriber_user must be null'})
+
super(ServiceDependency, self).save()
diff --git a/xos/core/models/attic/xoscomponentlink_model.py b/xos/core/models/attic/xoscomponentlink_model.py
index 413ce07..bfc5965 100644
--- a/xos/core/models/attic/xoscomponentlink_model.py
+++ b/xos/core/models/attic/xoscomponentlink_model.py
@@ -3,5 +3,5 @@
if not self.pk:
existing = XOSComponentLink.objects.filter(container=self.container, alias=self.alias)
if len(existing) > 0:
- raise XOSValidationError('XOSComponentLink for %s:%s already defined' % (self.container, self.alias))
+ raise XOSValidationError('XOSComponentLink for %s:%s already defined' % (self.container, self.alias), {'pk' : 'XOSComponentLink for %s:%s already defined' % (self.container, self.alias)})
super(XOSComponentLink, self).save(*args, **kwds)
diff --git a/xos/core/models/attic/xoscomponentvolume_model.py b/xos/core/models/attic/xoscomponentvolume_model.py
index a2ae229..8d6c7c7 100644
--- a/xos/core/models/attic/xoscomponentvolume_model.py
+++ b/xos/core/models/attic/xoscomponentvolume_model.py
@@ -3,6 +3,6 @@
if not self.pk:
existing = XOSComponentVolume.objects.filter(container_path=self.container_path, host_path=self.host_path)
if len(existing) > 0:
- raise XOSValidationError('XOSComponentVolume for %s:%s already defined' % (self.container_path, self.host_path))
+ raise XOSValidationError('XOSComponentVolume for %s:%s already defined' % (self.container_path, self.host_path), {'pk' : 'XOSComponentVolume for %s:%s already defined' % (self.container_path, self.host_path)})
super(XOSComponentVolume, self).save(*args, **kwds)
diff --git a/xos/core/models/attic/xoscomponentvolumecontainer_model.py b/xos/core/models/attic/xoscomponentvolumecontainer_model.py
index fda0b03..2509066 100644
--- a/xos/core/models/attic/xoscomponentvolumecontainer_model.py
+++ b/xos/core/models/attic/xoscomponentvolumecontainer_model.py
@@ -3,6 +3,6 @@
if not self.pk:
existing = XOSComponentVolumeContainer.objects.filter(name=self.name)
if len(existing) > 0:
- raise XOSValidationError('XOSComponentVolumeContainer for %s:%s already defined' % (self.container_path, self.host_path))
+ raise XOSValidationError('XOSComponentVolumeContainer for %s:%s already defined' % (self.container_path, self.host_path), {'pk' : 'XOSComponentVolumeContainer for %s:%s already defined' % (self.container_path, self.host_path)})
super(XOSComponentVolumeContainer, self).save(*args, **kwds)
diff --git a/xos/xos/apibase.py b/xos/xos/apibase.py
index addbbe9..8d80f38 100644
--- a/xos/xos/apibase.py
+++ b/xos/xos/apibase.py
@@ -23,7 +23,7 @@
serializer = self.get_serializer(self.object, data=request.data, partial=partial)
if not serializer.is_valid():
- raise XOSValidationError(fields=serializer._errors)
+ raise XOSValidationError('Invalid serializer', fields=serializer._errors)
# Do the XOS perm check
@@ -65,7 +65,7 @@
# In rest_framework 3.x: we can pass raise_exception=True instead of
# raising the exception ourselves
if not serializer.is_valid():
- raise XOSValidationError(fields=serializer._errors)
+ raise XOSValidationError('Invalid serializer', fields=serializer._errors)
# now do XOS can_update permission checking
obj = serializer.Meta.model(**serializer.validated_data)