mirror of
https://github.com/ansible/awx.git
synced 2026-01-20 06:01:25 -03:30
Merge pull request #2104 from YunfanZhang42/release_3.3.0
Fix job id incorrectly cast to string in ActiveJobConflict.
This commit is contained in:
commit
1255cfc2f0
@ -12,7 +12,11 @@ class ActiveJobConflict(ValidationError):
|
||||
status_code = 409
|
||||
|
||||
def __init__(self, active_jobs):
|
||||
super(ActiveJobConflict, self).__init__({
|
||||
# During APIException.__init__(), Django Rest Framework
|
||||
# turn everything in self.detail into string by using force_text.
|
||||
# Declare detail afterwards circumvent this behavior.
|
||||
super(ActiveJobConflict, self).__init__()
|
||||
self.detail = {
|
||||
"error": _("Resource is being used by running jobs."),
|
||||
"active_jobs": active_jobs
|
||||
})
|
||||
}
|
||||
|
||||
@ -466,7 +466,7 @@ class RelatedJobsMixin(object):
|
||||
return self._get_related_jobs().filter(status__in=ACTIVE_STATES)
|
||||
|
||||
'''
|
||||
Returns [{'id': '1', 'type': 'job'}, {'id': 2, 'type': 'project_update'}, ...]
|
||||
Returns [{'id': 1, 'type': 'job'}, {'id': 2, 'type': 'project_update'}, ...]
|
||||
'''
|
||||
def get_active_jobs(self):
|
||||
UnifiedJob = apps.get_model('main', 'UnifiedJob')
|
||||
@ -475,5 +475,5 @@ class RelatedJobsMixin(object):
|
||||
if not isinstance(jobs, QuerySet):
|
||||
raise RuntimeError("Programmer error. Expected _get_active_jobs() to return a QuerySet.")
|
||||
|
||||
return [dict(id=str(t[0]), type=mapping[t[1]]) for t in jobs.values_list('id', 'polymorphic_ctype_id')]
|
||||
return [dict(id=t[0], type=mapping[t[1]]) for t in jobs.values_list('id', 'polymorphic_ctype_id')]
|
||||
|
||||
|
||||
@ -73,12 +73,12 @@ def test_delete_instance_group_jobs(delete, instance_group_jobs_successful, inst
|
||||
@pytest.mark.django_db
|
||||
def test_delete_instance_group_jobs_running(delete, instance_group_jobs_running, instance_group_jobs_successful, instance_group, admin):
|
||||
def sort_keys(x):
|
||||
return (x['type'], x['id'])
|
||||
return (x['type'], str(x['id']))
|
||||
|
||||
url = reverse("api:instance_group_detail", kwargs={'pk': instance_group.pk})
|
||||
response = delete(url, None, admin, expect=409)
|
||||
|
||||
expect_transformed = [dict(id=str(j.id), type=j.model_to_str()) for j in instance_group_jobs_running]
|
||||
expect_transformed = [dict(id=j.id, type=j.model_to_str()) for j in instance_group_jobs_running]
|
||||
response_sorted = sorted(response.data['active_jobs'], key=sort_keys)
|
||||
expect_sorted = sorted(expect_transformed, key=sort_keys)
|
||||
|
||||
|
||||
@ -260,12 +260,12 @@ def test_organization_delete(delete, admin, organization, organization_jobs_succ
|
||||
@pytest.mark.django_db
|
||||
def test_organization_delete_with_active_jobs(delete, admin, organization, organization_jobs_running):
|
||||
def sort_keys(x):
|
||||
return (x['type'], x['id'])
|
||||
return (x['type'], str(x['id']))
|
||||
|
||||
url = reverse('api:organization_detail', kwargs={'pk': organization.id})
|
||||
resp = delete(url, None, user=admin, expect=409)
|
||||
|
||||
expect_transformed = [dict(id=str(j.id), type=j.model_to_str()) for j in organization_jobs_running]
|
||||
expect_transformed = [dict(id=j.id, type=j.model_to_str()) for j in organization_jobs_running]
|
||||
resp_sorted = sorted(resp.data['active_jobs'], key=sort_keys)
|
||||
expect_sorted = sorted(expect_transformed, key=sort_keys)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user