Skip to content

Fix: catch requests.ConnectionError in list_repo_templates#40158

Closed
laitifranz wants to merge 1 commit intohuggingface:mainfrom
laitifranz:fix/handle-requests-connection-error-in-list-repo-templates
Closed

Fix: catch requests.ConnectionError in list_repo_templates#40158
laitifranz wants to merge 1 commit intohuggingface:mainfrom
laitifranz:fix/handle-requests-connection-error-in-list-repo-templates

Conversation

@laitifranz
Copy link
Copy Markdown

What does this PR do?

This PR fixes a bug in the list_repo_templates function where network connectivity issues would cause the entire function to crash instead of gracefully falling back to local files.

Problem

When used without an internet connection, the function raised:

    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/models/Qwen/Qwen2.5-VL-7B-Instruct/tree/main/additional_chat_templates?recursive=False&expand=False (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x14cdd4b28b60>: Failed to establish a new connection: [Errno 101] Network is unreachable'))"), '(Request ID: ---)')

The exception handler only caught Python’s built-in ConnectionError, not the requests-specific one, so the fallback logic never ran.

Fix

Add requests.exceptions.ConnectionError to the exception handler.

Now, if the network is unavailable, the function correctly falls back to local cached templates as intended.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • [x ] Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@Rocketknight1

@Rocketknight1
Copy link
Copy Markdown
Member

We have a PR for this already! #39874

@laitifranz
Copy link
Copy Markdown
Author

Thanks for pointing that out and for merging the fix recently! I’ll close this PR in favor of #39874

@laitifranz laitifranz closed this Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants