Skip to content

Commit 44d16ce

Browse files
authored
Fix #1171: fix attachment context lost when refetching from server (#1172)
1 parent 114a0d3 commit 44d16ce

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

jbi/bugzilla/service.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ def refresh_bug_data(self, bug: Bug):
4040
"""Re-fetch a bug to ensure we have the most up-to-date data"""
4141

4242
refreshed_bug_data = self.client.get_bug(bug.id)
43-
# When bugs come in as webhook payloads, they have a "comment"
44-
# attribute, but this field isn't available when we get a bug by ID.
45-
# So, we make sure to add the comment back if it was present on the bug.
46-
updated_bug = refreshed_bug_data.model_copy(update={"comment": bug.comment})
43+
# When bugs come in as webhook payloads, they have "comment" and "attachment"
44+
# attributes, but these fields aren't available when we get a bug by ID.
45+
# So, we make sure to add them back if they were present on the bug.
46+
updated_bug = refreshed_bug_data.model_copy(
47+
update={
48+
"comment": bug.comment,
49+
"attachment": bug.attachment,
50+
}
51+
)
4752
return updated_bug
4853

4954
def list_webhooks(self):

tests/unit/bugzilla/test_service.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pytest
2+
3+
from jbi import bugzilla
4+
5+
6+
@pytest.fixture
7+
def bugzilla_client(settings):
8+
return bugzilla.client.BugzillaClient(
9+
base_url=settings.bugzilla_base_url, api_key=settings.bugzilla_api_key
10+
)
11+
12+
13+
@pytest.fixture
14+
def bugzilla_service(bugzilla_client):
15+
return bugzilla.service.BugzillaService(bugzilla_client)
16+
17+
18+
def test_refresh_bug_data_keeps_comment_and_attachment(
19+
bugzilla_service, mocked_responses, bug_factory, settings
20+
):
21+
bug = bug_factory(with_attachment=True, with_comment=True)
22+
# https://bugzilla.readthedocs.io/en/latest/api/core/v1/bug.html#get-bug
23+
mocked_responses.add(
24+
"GET",
25+
f"{settings.bugzilla_base_url}/rest/bug/%s" % bug.id,
26+
json={
27+
"bugs": [
28+
{
29+
"id": bug.id,
30+
}
31+
],
32+
},
33+
)
34+
35+
updated = bugzilla_service.refresh_bug_data(bug)
36+
37+
assert updated.comment == bug.comment
38+
assert updated.attachment == bug.attachment

0 commit comments

Comments
 (0)