Skip to content

Fix #1171: fix attachment context lost when refetching from server #1172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions jbi/bugzilla/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ def refresh_bug_data(self, bug: Bug):
"""Re-fetch a bug to ensure we have the most up-to-date data"""

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

def list_webhooks(self):
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/bugzilla/test_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest

from jbi import bugzilla


@pytest.fixture
def bugzilla_client(settings):
return bugzilla.client.BugzillaClient(
base_url=settings.bugzilla_base_url, api_key=settings.bugzilla_api_key
)


@pytest.fixture
def bugzilla_service(bugzilla_client):
return bugzilla.service.BugzillaService(bugzilla_client)


def test_refresh_bug_data_keeps_comment_and_attachment(
bugzilla_service, mocked_responses, bug_factory, settings
):
bug = bug_factory(with_attachment=True, with_comment=True)
# https://bugzilla.readthedocs.io/en/latest/api/core/v1/bug.html#get-bug
mocked_responses.add(
"GET",
f"{settings.bugzilla_base_url}/rest/bug/%s" % bug.id,
json={
"bugs": [
{
"id": bug.id,
}
],
},
)

updated = bugzilla_service.refresh_bug_data(bug)

assert updated.comment == bug.comment
assert updated.attachment == bug.attachment
Loading