1010from src .app .environment import get_settings
1111from src .jbi .bugzilla import BugzillaBug , BugzillaWebhookRequest
1212from src .jbi .errors import ActionError
13- from src .jbi .services import get_bugzilla , get_jira , getbug_as_bugzilla_object
13+ from src .jbi .services import get_bugzilla , get_jira
1414
1515settings = get_settings ()
1616
@@ -41,11 +41,9 @@ def __call__( # pylint: disable=inconsistent-return-statements
4141 """Called from BZ webhook when default action is used. All default-action webhook-events are processed here."""
4242 target = payload .event .target # type: ignore
4343 if target == "comment" :
44- bug_obj = payload .bug
45- return self .comment_create_or_noop (payload = payload , bug_obj = bug_obj ) # type: ignore
44+ return self .comment_create_or_noop (payload = payload ) # type: ignore
4645 if target == "bug" :
47- bug_obj = getbug_as_bugzilla_object (payload )
48- return self .bug_create_or_update (payload = payload , bug_obj = bug_obj )
46+ return self .bug_create_or_update (payload = payload )
4947 logger .debug (
5048 "Ignore event target %r" ,
5149 target ,
@@ -54,10 +52,9 @@ def __call__( # pylint: disable=inconsistent-return-statements
5452 },
5553 )
5654
57- def comment_create_or_noop (
58- self , payload : BugzillaWebhookRequest , bug_obj : BugzillaBug
59- ):
55+ def comment_create_or_noop (self , payload : BugzillaWebhookRequest ):
6056 """Confirm issue is already linked, then apply comments; otherwise noop"""
57+ bug_obj = payload .bugzilla_object
6158 linked_issue_key = bug_obj .extract_from_see_also ()
6259
6360 log_context = {
@@ -100,9 +97,10 @@ def update_issue(
10097 """Allows sub-classes to modify the Jira issue in response to a bug event"""
10198
10299 def bug_create_or_update (
103- self , payload : BugzillaWebhookRequest , bug_obj : BugzillaBug
100+ self , payload : BugzillaWebhookRequest
104101 ): # pylint: disable=too-many-locals
105102 """Create and link jira issue with bug, or update; rollback if multiple events fire"""
103+ bug_obj = payload .bugzilla_object
106104 linked_issue_key = bug_obj .extract_from_see_also () # type: ignore
107105 if not linked_issue_key :
108106 return self .create_and_link_issue (payload , bug_obj )
@@ -180,7 +178,10 @@ def create_and_link_issue(
180178 raise ActionError (f"response contains error: { jira_response_create } " )
181179
182180 jira_key_in_response = jira_response_create .get ("key" )
183- bug_obj = getbug_as_bugzilla_object (request = payload )
181+
182+ # In the time taken to create the Jira issue the bug may have been updated so
183+ # re-retrieve it to ensure we have the latest data.
184+ bug_obj = payload .getbug_as_bugzilla_object ()
184185 jira_key_in_bugzilla = bug_obj .extract_from_see_also ()
185186 _duplicate_creation_event = (
186187 jira_key_in_bugzilla is not None
0 commit comments