Skip to content

Commit bb3e46f

Browse files
committed
Fix bug where latest email timestamp of patch was outdated
1 parent 5389294 commit bb3e46f

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

pgcommitfest/commitfest/ajax.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ def refresh_single_thread(thread):
117117
parse_and_add_attachments(r, thread)
118118
# Potentially update the last mail date - if there wasn't already a mail on each patch
119119
# from a *different* thread that had an earlier date.
120-
for p in thread.patches.filter(lastmail__lt=thread.latestmessage):
121-
p.lastmail = thread.latestmessage
120+
new_latestmessage = r[-1]["date"]
121+
for p in thread.patches.filter(lastmail__lt=new_latestmessage):
122+
p.lastmail = new_latestmessage
122123
p.save()
123124

124125
# Finally, we update the thread entry itself. We should only do that at
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from datetime import datetime
2+
from unittest.mock import patch
3+
4+
import pytest
5+
6+
from pgcommitfest.commitfest.ajax import refresh_single_thread
7+
from pgcommitfest.commitfest.models import MailThread, Patch, Topic
8+
9+
pytestmark = pytest.mark.django_db
10+
11+
12+
def test_refresh_single_thread_updates_patch_lastmail():
13+
"""Regression test: patch.lastmail should get the new date, not the old one."""
14+
old_date = datetime(2024, 1, 1)
15+
new_date = datetime(2024, 6, 15)
16+
17+
topic = Topic.objects.create(topic="Test")
18+
thread = MailThread.objects.create(
19+
messageid="old@example.com",
20+
subject="Test",
21+
firstmessage=old_date,
22+
firstauthor="a@example.com",
23+
latestmessage=old_date,
24+
latestauthor="a@example.com",
25+
latestsubject="Test",
26+
latestmsgid="old@example.com",
27+
)
28+
p = Patch.objects.create(name="Test Patch", topic=topic, lastmail=old_date)
29+
p.mailthread_set.add(thread)
30+
31+
api_response = [
32+
{
33+
"msgid": "old@example.com",
34+
"date": old_date,
35+
"from": "a",
36+
"subj": "T",
37+
"atts": [],
38+
},
39+
{
40+
"msgid": "new@example.com",
41+
"date": new_date,
42+
"from": "b",
43+
"subj": "T",
44+
"atts": [],
45+
},
46+
]
47+
48+
with patch("pgcommitfest.commitfest.ajax._archivesAPI", return_value=api_response):
49+
refresh_single_thread(thread)
50+
51+
p.refresh_from_db()
52+
assert p.lastmail == new_date

0 commit comments

Comments
 (0)