From a9f6a6db9abd7dc6d7f141cfead1f4c3019acc98 Mon Sep 17 00:00:00 2001 From: ANJAN672 Date: Sat, 17 Jan 2026 10:46:28 +0000 Subject: [PATCH] fix: prevent NameError from uninitialized keys variable - Initialize keys=[] before retry loop to prevent NameError if all database attempts fail - Replace bare except: with except Exception for better debugging - Add logging for failed database attempts - Remove unused variable assignment (valid_now) and dead commented code Fixes #3602 Signed-off-by: ANJAN672 --- .../tasks/github/util/github_api_key_handler.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/augur/tasks/github/util/github_api_key_handler.py b/augur/tasks/github/util/github_api_key_handler.py index 47933e67dc..7cc8476cdc 100644 --- a/augur/tasks/github/util/github_api_key_handler.py +++ b/augur/tasks/github/util/github_api_key_handler.py @@ -92,13 +92,15 @@ def get_api_keys(self) -> List[str]: if redis_keys: return redis_keys + # Initialize keys to empty list to prevent NameError if all retries fail + keys = [] attempts = 0 while attempts < 3: - try: keys = self.get_api_keys_from_database() break - except: + except Exception as e: + self.logger.warning(f"Failed to get API keys from database (attempt {attempts + 1}/3): {e}") time.sleep(5) attempts += 1 @@ -132,16 +134,6 @@ def get_api_keys(self) -> List[str]: raise NoValidKeysError("No valid github api keys found in the config or worker oauth table") - # shuffling the keys so not all processes get the same keys in the same order - valid_now = valid_keys - #try: - #self.logger.info(f'valid keys before shuffle: {valid_keys}') - #valid_keys = random.sample(valid_keys, len(valid_keys)) - #self.logger.info(f'valid keys AFTER shuffle: {valid_keys}') - #except Exception as e: - # self.logger.debug(f'{e}') - # valid_keys = valid_now - # pass return valid_keys