diff --git a/awx/api/serializers.py b/awx/api/serializers.py index e171f3b232..0bbdfa35c6 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1393,13 +1393,15 @@ class ProjectSerializer(UnifiedJobTemplateSerializer, ProjectOptionsSerializer): if 'allow_override' in attrs and self.instance: # case where user is turning off this project setting if self.instance.allow_override and not attrs['allow_override']: - used_by = ( - set(JobTemplate.objects.filter(project=self.instance, scm_branch__isnull=False).values_list('pk', flat=True)) | - set(JobTemplate.objects.filter(project=self.instance, ask_scm_branch_on_launch=True).values_list('pk', flat=True)) + used_by = set( + JobTemplate.objects.filter( + models.Q(project=self.instance), + models.Q(ask_scm_branch_on_launch=True) | ~models.Q(scm_branch="") + ).values_list('pk', flat=True) ) if used_by: raise serializers.ValidationError({ - 'allow_override': _('One or more job templates already specify a branch for this project (ids: {}).').format( + 'allow_override': _('One or more job templates depend on branch override behavior for this project (ids: {}).').format( ' '.join([str(pk) for pk in used_by]) )}) diff --git a/awx/main/tests/functional/api/test_project.py b/awx/main/tests/functional/api/test_project.py index 003934b12d..571d0624fb 100644 --- a/awx/main/tests/functional/api/test_project.py +++ b/awx/main/tests/functional/api/test_project.py @@ -70,7 +70,7 @@ def test_no_changing_overwrite_behavior_if_used(post, patch, organization, admin user=admin_user, expect=400 ) - assert 'job templates already specify a branch for this project' in str(r2.data['allow_override']) + assert 'job templates depend on branch override behavior for this project' in str(r2.data['allow_override']) assert 'ids: 2' in str(r2.data['allow_override']) assert Project.objects.get(pk=r1.data['id']).allow_override is True