Whoa, I found a bug

I hit this error when just trying to access the sweeps under a project.

api = wandb.Api()
project = api.project(project_name)

The project name and login are not the problem, since I can iterate over the runs in a project without issue:

project_name = "robin-radar/IrisFastAI_new_arch"
runs = api.runs(project_name)

This is the stack trace of the error. It mentions “Whoa, you found a bug” in the stacktrace.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File ~/mambaforge-pypy3/envs/fastai_env/lib/python3.10/site-packages/wandb/apis/normalize.py:41, in normalize_exceptions.<locals>.wrapper(*args, **kwargs)
     40 try:
---> 41     return func(*args, **kwargs)
     42 except requests.HTTPError as error:

File ~/mambaforge-pypy3/envs/fastai_env/lib/python3.10/site-packages/wandb/apis/public.py:1687, in Project.sweeps(self)
   1686 ret = self.client.execute(query, variable_values)
-> 1687 if ret["project"]["totalSweeps"] < 1:
   1688     return []

TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

CommError                                 Traceback (most recent call last)
/home/tim.kuipers/dev/deeplearning/projects/iris_drone_classification/pipeline_2023_fastai2/analyze_sweep.ipynb Cell 13 line 7
      4 project = api.project(project_name)
      5 log_uniform_params = set()
----> 7 for sweep in project.sweeps():
      8     config = sweep.config
      9     hyperparameter_ranges = config.get('parameters', {})

File ~/mambaforge-pypy3/envs/fastai_env/lib/python3.10/site-packages/wandb/apis/normalize.py:87, in normalize_exceptions.<locals>.wrapper(*args, **kwargs)
     85     raise
     86 else:
---> 87     raise CommError(message, err).with_traceback(sys.exc_info()[2])

File ~/mambaforge-pypy3/envs/fastai_env/lib/python3.10/site-packages/wandb/apis/normalize.py:41, in normalize_exceptions.<locals>.wrapper(*args, **kwargs)
     39 message = "Whoa, you found a bug."
     40 try:
---> 41     return func(*args, **kwargs)
     42 except requests.HTTPError as error:
     43     errors = parse_backend_error_messages(error.response)

File ~/mambaforge-pypy3/envs/fastai_env/lib/python3.10/site-packages/wandb/apis/public.py:1687, in Project.sweeps(self)
   1685 variable_values = {"project": self.name, "entity": self.entity}
   1686 ret = self.client.execute(query, variable_values)
-> 1687 if ret["project"]["totalSweeps"] < 1:
   1688     return []
   1690 return [
   1691     # match format of existing public sweep apis
   1692     Sweep(
   (...)
   1704     for e in ret["project"]["sweeps"]["edges"]
   1705 ]

CommError: 'NoneType' object is not subscriptable

I did find a workaround:

for run in runs:
    if run.config.get('sweep_id') is not None: continue # only consider sweeps, not actual runs
    sweep = run.sweep

Hey @tim-kuipers whoa, thank you for reporting this issue :grinning:

The api.project() accepts name and entity as arguments, in contrast to api.runs(). Could you please adjust your code as follows:

project = api.project(name='IrisFastAI_new_arch', entity='robin-radar')
for sweep in project.sweeps():
  print(sweep.name)

Would it work this way for you?

Yeah that was it. It was a matter of not looking at the api thoroughly enough.

BTW: why does the function have a parameter default of entity=None? I would assume that the entity should never be None…?

Hi @tim-kuipers great, glad to hear this worked for you! Regarding the follow-up question, the entity isn’t always essential to be provided, as it could be read either from environment variable WANDB_ENTITY (if that’s been exported) or by default values in wandb/settings file. However, to ensure you’re logging into the correct entity of yours (in case you’re also part of teams) the best practice would be to specify that too. I hope this helps!

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.