mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 06:17:36 -02:30
deal with a special null null case
This commit is contained in:
@@ -207,7 +207,6 @@ class BaseAccess(object):
|
|||||||
'''
|
'''
|
||||||
new = None
|
new = None
|
||||||
changed = True
|
changed = True
|
||||||
is_removal = False
|
|
||||||
if data and 'reference_obj' in data:
|
if data and 'reference_obj' in data:
|
||||||
# Use reference object's related fields, if given
|
# Use reference object's related fields, if given
|
||||||
new = getattr(data['reference_obj'], field)
|
new = getattr(data['reference_obj'], field)
|
||||||
@@ -218,7 +217,6 @@ class BaseAccess(object):
|
|||||||
new = raw_value
|
new = raw_value
|
||||||
elif raw_value is None:
|
elif raw_value is None:
|
||||||
new = None
|
new = None
|
||||||
is_removal = True
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
new_pk = int(raw_value)
|
new_pk = int(raw_value)
|
||||||
@@ -238,7 +236,7 @@ class BaseAccess(object):
|
|||||||
if obj and (changed or mandatory):
|
if obj and (changed or mandatory):
|
||||||
current = getattr(obj, field)
|
current = getattr(obj, field)
|
||||||
|
|
||||||
if obj and new == current and (not is_removal):
|
if obj and new == current:
|
||||||
# Resource not changed, like a PUT request
|
# Resource not changed, like a PUT request
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,14 @@ class TestRelatedFieldAccess:
|
|||||||
assert not access.check_related(
|
assert not access.check_related(
|
||||||
'related', mocker.MagicMock, data, obj=resource_bad)
|
'related', mocker.MagicMock, data, obj=resource_bad)
|
||||||
|
|
||||||
|
def test_existing_not_null_null(self, access, bad_role, mocker):
|
||||||
|
resource = mocker.MagicMock(related=None)
|
||||||
|
data = {'related': None}
|
||||||
|
# Not changing anything by giving null when it is already-null
|
||||||
|
# important for PUT requests
|
||||||
|
assert access.check_related(
|
||||||
|
'related', mocker.MagicMock, data, obj=resource, mandatory=True)
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def job_template_with_ids(job_template_factory):
|
def job_template_with_ids(job_template_factory):
|
||||||
# Create non-persisted objects with IDs to send to job_template_factory
|
# Create non-persisted objects with IDs to send to job_template_factory
|
||||||
|
|||||||
Reference in New Issue
Block a user