From 891fa39cbc8974abb68340f26a1951754d9f4cd8 Mon Sep 17 00:00:00 2001 From: "Mr. Senko" Date: Tue, 21 Jan 2020 14:39:19 +0200 Subject: [PATCH] Fix TestCase.update() handling of unspecified fields. Fixes #1318 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. --- tcms/rpc/api/forms/testcase.py | 4 +++- tcms/rpc/api/testcase.py | 7 ------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/tcms/rpc/api/forms/testcase.py b/tcms/rpc/api/forms/testcase.py index 83882e2f3d..32ece842e3 100644 --- a/tcms/rpc/api/forms/testcase.py +++ b/tcms/rpc/api/forms/testcase.py @@ -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 diff --git a/tcms/rpc/api/testcase.py b/tcms/rpc/api/testcase.py index 6b7abd3452..6c1c5ed85b 100644 --- a/tcms/rpc/api/testcase.py +++ b/tcms/rpc/api/testcase.py @@ -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():