chaoss / chaoss/CollectOSS

Bug: Uninitialized variable in github_api_key_handler.py causes NameError

Open
#181 0 comments 0 reactions 0 assignees View on GitHub
theoretical
Dominant language
Python
Stars
13
Forks
17
Avg merge
6h 59m
Merged PRs (30d)
1

Description

> [!NOTE]
> Migrated from [augurlabs/augur#3602](https://github.com/augurlabs/augur/issues/3602)
> Originally opened by `@ANJAN672` on 2026-01-17

---

## Description

In `augur/tasks/github/util/github_api_key_handler.py`, the `get_api_keys()` method has a bug where the `keys` variable may be uninitialized.

## The Problem

```python
# Lines 95-106
attempts = 0
while attempts < 3:
try:
keys = self.get_api_keys_from_database() # Only defined here
break
except:
time.sleep(5)
attempts += 1

if self.config_key is not None:
keys += [self.config_key] # 💥 NameError if all 3 attempts failed!
```

If `get_api_keys_from_database()` fails all 3 retry attempts, the `keys` variable is **never defined**, causing:
```
NameError: name 'keys' is not defined
```

## Additional Issues in Same Function

1. **Bare `except:`** on line 101 - should be `except Exception as e:` for better debugging
2. **Unused variable** on line 136 - `valid_now = valid_keys` is assigned but never used

## Proposed Fix

Initialize `keys = []` before the while loop, and clean up the other issues.

## I'm working on this

I'll submit a PR shortly.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.