Skip to content

Commit 1cfebfd

Browse files
committed
Fall back to create_date when updated_at is null
For records that existed before the updated_at migration, the field is null. Show create_date instead in detail views, filter responses and update responses for both TestCase and TestPlan.
1 parent ad62c78 commit 1cfebfd

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

tcms/rpc/api/testcase.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,11 @@ def filter(query=None): # pylint: disable=redefined-builtin
306306
.distinct()
307307
)
308308

309-
return list(qs)
309+
result = list(qs)
310+
for item in result:
311+
if item["updated_at"] is None:
312+
item["updated_at"] = item["create_date"]
313+
return result
310314

311315

312316
@permissions_required("testcases.view_testcase")
@@ -383,7 +387,7 @@ def update(case_id, values):
383387
result = model_to_dict(test_case, exclude=["component", "plan", "tag"])
384388
# b/c date may be None and model_to_dict() doesn't return it
385389
result["create_date"] = test_case.create_date
386-
result["updated_at"] = test_case.updated_at
390+
result["updated_at"] = test_case.updated_at or test_case.create_date
387391

388392
# additional information
389393
result["case_status__name"] = test_case.case_status.name

tcms/rpc/api/testplan.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def filter(query=None): # pylint: disable=redefined-builtin
8787
if query is None:
8888
query = {}
8989

90-
return list(
90+
result = list(
9191
TestPlan.objects.filter(**query)
9292
.values(
9393
"id",
@@ -111,6 +111,10 @@ def filter(query=None): # pylint: disable=redefined-builtin
111111
.order_by("product", "id")
112112
.distinct()
113113
)
114+
for item in result:
115+
if item["updated_at"] is None:
116+
item["updated_at"] = item["create_date"]
117+
return result
114118

115119

116120
@permissions_required("testplans.add_testplantag")
@@ -183,7 +187,7 @@ def update(plan_id, values):
183187
# b/c value is set in the DB directly and if None
184188
# model_to_dict() will not return it
185189
result["create_date"] = test_plan.create_date
186-
result["updated_at"] = test_plan.updated_at
190+
result["updated_at"] = test_plan.updated_at or test_plan.create_date
187191
return result
188192

189193
raise ValueError(list(form.errors.items()))

tcms/testcases/templates/testcases/get.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ <h2 class="card-pf-title kiwi-text-align-left">
7171

7272
<h2 class="card-pf-title kiwi-text-align-left">
7373
<span class="fa fa-pencil"></span>{% trans 'Last modified' %}:
74-
{{ object.updated_at|default:"-" }}
74+
{{ object.updated_at|default:object.create_date }}
7575
</h2>
7676

7777
<h2 class="card-pf-title kiwi-text-align-left">

tcms/testplans/templates/testplans/get.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h2 class="card-pf-title kiwi-text-align-left">
6161

6262
<h2 class="card-pf-title kiwi-text-align-left">
6363
<span class="fa fa-pencil"></span>{% trans 'Last modified' %}:
64-
{{ object.updated_at|default:"-" }}
64+
{{ object.updated_at|default:object.create_date }}
6565
</h2>
6666

6767
<h2 class="card-pf-title kiwi-text-align-left">

0 commit comments

Comments
 (0)