From d3e63c75012e76520dbd3523a93d0b7a965005ce Mon Sep 17 00:00:00 2001 From: Arkadiusz Komarzewski Date: Sun, 13 Sep 2026 18:30:02 +0200 Subject: [PATCH] Handle 404 from Bugzilla user lookup in probe expiry alerts Bugzilla now returns HTTP 404 (still with error code 51) when a user does not exist. check_bugzilla_user_exists only handled 400, so the first probe with an alert email that has no Bugzilla account (passwords-dev@mozilla.org, PWMGR_IMPORT_LOGINS_FROM_FILE_CATEGORICAL expiring in 160) made probe-expiry-alerts fail with an unhandled HTTPError. The task has been failing daily since 2026-09-10. Treat code 51 as "user not found" for both 400 and 404, and cover both status codes in the test. --- probe_scraper/probe_expiry_alert.py | 5 +++-- tests/test_probe_expiry_alert.py | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/probe_scraper/probe_expiry_alert.py b/probe_scraper/probe_expiry_alert.py index 98dffb37..4459ea9a 100644 --- a/probe_scraper/probe_expiry_alert.py +++ b/probe_scraper/probe_expiry_alert.py @@ -287,8 +287,9 @@ def check_bugzilla_user_exists(email: str, api_key: str): try: user_response.raise_for_status() except requests.exceptions.HTTPError as e: - # 400 is raised if user does not exist - if e.response.status_code == 400 and e.response.json()["code"] == 51: + # Error code 51 means the user does not exist. Bugzilla used to return + # it with HTTP 400 and now returns it with HTTP 404. + if e.response.status_code in (400, 404) and e.response.json()["code"] == 51: return False raise # As of Sept 2020, api seems to be returning 200 response with an unknown diff --git a/tests/test_probe_expiry_alert.py b/tests/test_probe_expiry_alert.py index b47b346f..7ec4bcf6 100644 --- a/tests/test_probe_expiry_alert.py +++ b/tests/test_probe_expiry_alert.py @@ -3,6 +3,7 @@ from dataclasses import dataclass from unittest import mock +import pytest from requests.exceptions import HTTPError from probe_scraper import probe_expiry_alert @@ -493,10 +494,11 @@ def test_get_longest_prefix(): assert probe_expiry_alert.get_longest_prefix(["abc"]) == "abc" +@pytest.mark.parametrize("status_code", [400, 404]) @mock.patch("requests.get") -def test_check_bugzilla_user_account_not_found(mock_get): +def test_check_bugzilla_user_account_not_found(mock_get, status_code): mock_response = mock.MagicMock() - mock_response.status_code = 400 + mock_response.status_code = status_code mock_response.json = mock.MagicMock(return_value={"code": 51}) def user_not_found():