in treeherder/model/models.py [0:0]
def create(cls, *, job_id, internal_bug_id=None, bugzilla_id=None, user=None, bug_open=False):
if (bool(internal_bug_id) ^ bool(bugzilla_id)) is False:
raise ValueError("Only one of internal bug ID or Bugzilla ID must be set")
if internal_bug_id:
bug_reference = {"bug_id": internal_bug_id}
else:
# Try mapping Bugzilla ID to internal reference of a bug
try:
bug_reference = {
"bug_id": Bugscache.objects.only("id").get(bugzilla_id=bugzilla_id).id
}
except Bugscache.DoesNotExist:
raise ValueError(f"No bug found with Bugzilla ID {bugzilla_id}")
bug_map = BugJobMap.objects.create(
job_id=job_id, user=user, bug_open=bug_open, **bug_reference
)
if not user:
return bug_map
# We have a user so this wasn't triggered by auto-classification.
# However we need to update the ClassifiedFailure with the bug number
# we just used to create the BugJobMap.
text_log_error = bug_map.job.get_manual_classification_line()
if text_log_error is None:
return bug_map
classification = (
text_log_error.metadata.best_classification if text_log_error.metadata else None
)
if (
bugzilla_id
# no classification to update
and classification is not None
# classification already has a bug number
and not classification.bug_number
):
classification.set_bug(bugzilla_id)
return bug_map