mamba-org/quetz

First level attribute can be unbound

Closed this issue · 1 comments

There is a change that you never enter the while loop, which makes the first_level attribute undefined.

quetz/quetz/config.py

Lines 395 to 408 in efcfdb8

idx = 2
# look for the first level of config_map.
# It must be done in loop as the key itself can contains '_'.
while idx < len(splitted_key):
first_level = self._find_first_level_config(config_key)
if first_level:
break
config_key += f"_{ splitted_key[idx].lower()}"
idx += 1
# no first_level found, the variable is useless.
if not first_level:
continue

This can cause the following error.

UnboundLocalError: cannot access local variable 'first_level' where it is not associated with a value

I feel like this should have been caught by some pre-commit hook (e.g. mypy).

Doesn't seem to be so easy to catch this with a pre-commit hook (see python/mypy#2400).