Skip to content

Commit

Permalink
Fix TestCase.update() handling of unspecified fields. Fixes #1318
Browse files Browse the repository at this point in the history
this still allows the API caller to specify only the fields which
they want to modify but properly initializes the rest of the values
based on the current object instance instead of reseting them
to None.
  • Loading branch information
atodorov committed Jan 21, 2020
1 parent b7ad27e commit 891fa39
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
4 changes: 3 additions & 1 deletion tcms/rpc/api/forms/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
)

for field in self.fields:
self.fields[field].required = False
# will cause BaseForm._clean_fields() to reuse the value
# from self.initial (<-- self.instance) if not specified
self.fields[field].disabled = field not in data
7 changes: 0 additions & 7 deletions tcms/rpc/api/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,6 @@ def update(case_id, values):
:raises: PermissionDenied if missing *testcases.change_testcase* permission
"""
test_case = TestCase.objects.get(pk=case_id)

# initialize mandatory values for FK fields if they are
# not specified by the caller
for fk_field in ('author', 'case_status', 'category', 'priority'):
if not (values.get(fk_field) or values.get(fk_field + '_id')):
values[fk_field] = getattr(test_case, fk_field + '_id')

form = UpdateForm(values, instance=test_case)

if form.is_valid():
Expand Down

0 comments on commit 891fa39

Please sign in to comment.