Garden-AI / garden

https://garden-ai.readthedocs.io
MIT License
21 stars 4 forks source link

bug: `AttributeError: 'NoneType' object has no attribute 'file_format'` #548

Closed OwenPriceSkelly closed 1 month ago

OwenPriceSkelly commented 1 month ago

When trying to start a notebook without a requirements file, the widget cell might panic with the following stacktrace:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:21                                                                                   │
│                                                                                                  │
│   18 """                                                                                         │
│   19                                                                                             │
│   20 from garden_ai.notebook_metadata import display_metadata_widget                             │
│ ❱ 21 display_metadata_widget()                                                                   │
│   22                                                                                             │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/garden_ai/notebook_metadata.py:490 in                    │
│ display_metadata_widget                                                                          │
│                                                                                                  │
│   487 │   │   update_reqs_widget,                                                                │
│   488 │   │   accordion_widget,                                                                  │
│   489 │   │   metadata_widget,                                                                   │
│ ❱ 490 │   ) = _build_metadata_widgets(nb_meta)                                                   │
│   491 │                                                                                          │
│   492 │   # Setup event handlers                                                                 │
│   493 │   doi_widget.observe(doi_observer(nb_meta, metadata_widget, output), "value")            │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/garden_ai/notebook_metadata.py:281 in                    │
│ _build_metadata_widgets                                                                          │
│                                                                                                  │
│   278 def _build_metadata_widgets(nb_meta: NotebookMetadata) -> list[widgets.Widget]:            │
│   279 │   doi_widget = _build_doi_widget(nb_meta)                                                │
│   280 │   base_image_widget = _build_base_image_widget(nb_meta)                                  │
│ ❱ 281 │   reqs_widget = _build_reqs_widget(nb_meta)                                              │
│   282 │   update_reqs_widget = _build_update_reqs_widget(                                        │
│   283 │   │   description="Install new requirements"                                             │
│   284 │   )                                                                                      │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/garden_ai/notebook_metadata.py:240 in _build_reqs_widget │
│                                                                                                  │
│   237                                                                                            │
│   238                                                                                            │
│   239 def _build_reqs_widget(nb_meta: NotebookMetadata) -> widgets.Textarea:                     │
│ ❱ 240 │   if nb_meta.notebook_requirements.file_format == "pip":  # type: ignore                 │
│   241 │   │   reqs_string = "\n".join([req for req in nb_meta.notebook_requirements.contents])   │
│   242 │   else:                                                                                  │
│   243 │   │   # ignoring conda requirements, since we are planning to remove support for them    │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'NoneType' object has no attribute 'file_format'

I think this is related to a few other issues we've seen recently, including #522