From 850f03331bfc4579451450b6b1fc613f999b8d67 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Fri, 14 Jul 2017 15:48:29 -0400 Subject: [PATCH] tweaks to SCM inventory related validation errors --- awx/api/serializers.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 3ce740134e..0bbab1cc07 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1638,7 +1638,7 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt return ret def validate_source_project(self, value): - if value.scm_type == '': + if value and value.scm_type == '': raise serializers.ValidationError(_("Can not use manual project for SCM-based inventory.")) return value @@ -1648,6 +1648,11 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt "Manual inventory sources are created automatically when a group is created in the v1 API.")) return value + def validate_update_on_project_update(self, value): + if value and self.instance and self.instance.schedules.exists(): + raise serializers.ValidationError(_("Setting not compatible with existing schedules.")) + return value + def validate(self, attrs): def get_field_from_model_or_attrs(fd): return attrs.get(fd, self.instance and getattr(self.instance, fd) or None) @@ -3418,7 +3423,7 @@ class ScheduleSerializer(BaseSerializer): raise serializers.ValidationError(_('Manual Project can not have a schedule set.')) elif type(value) == InventorySource and value.source == 'scm' and value.update_on_project_update: raise serializers.ValidationError(_( - 'Inventory sources with `update_on_project_update` can not be shceduled. ' + 'Inventory sources with `update_on_project_update` cannot be scheduled. ' 'Schedule its source project `{}` instead.'.format(value.source_project.name))) return value