Skip to content

Commit

Permalink
Bug Fix: Update hub.py to fix NoneType error (huggingface#33315)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rishiraj authored and BernardZach committed Dec 5, 2024
1 parent a63bf1a commit cf58d00
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/transformers/utils/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cf58d00

Please sign in to comment.