Bug Fix: Update hub.py to fix NoneType error (#33315)

* Bug Fix: Update hub.py

Bug:
TypeError: argument of type 'NoneType' is not iterable

Analysis:
The error `TypeError: argument of type 'NoneType' is not iterable` suggests that `model_card.data.tags` is `None`, and the code is trying to iterate through it using `not in`.

Fix:

1. **Check if `model_card.data.tags` is `None` before the loop**:
   Since you're checking the variable `tags` before the loop, you should also ensure that `model_card.data.tags` is not `None`. You can do this by initializing `model_card.data.tags` to an empty list if it's `None`.

2. **Updated code**:
   Add a check and initialize the `tags` if it is `None` before proceeding with the iteration.

This way, if `model_card.data.tags` is `None`, it gets converted to an empty list before checking the contents. This prevents the `TypeError`.

* Update hub.py
This commit is contained in:
Rishiraj Acharya 2024-09-10 20:09:19 +05:30 committed by GitHub
parent 96429e74a8
commit 6ed2b10942
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1198,6 +1198,9 @@ def create_and_tag_model_card(
model_card = ModelCard.from_template(card_data, model_description=model_description)
if tags is not None:
# Ensure model_card.data.tags is a list and not None
if model_card.data.tags is None:
model_card.data.tags = []
for model_tag in tags:
if model_tag not in model_card.data.tags:
model_card.data.tags.append(model_tag)