Skip to content

Commit 002b31a

Browse files
Add a blog post about improved error handling for oauth2 configuration without internet (#2850)
Co-authored-by: Martin Hjelmare <[email protected]>
1 parent c8d38d3 commit 002b31a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
author: Will Moss
3+
authorURL: https://github.com/wmoss
4+
title: "Improved error handling for oauth2 configuration without internet"
5+
---
6+
7+
Integrations using [Application Credentials](https://developers.home-assistant.io/docs/core/platform/application_credentials/) and [Configuration via OAuth2](https://developers.home-assistant.io/docs/config_entries_config_flow_handler/#configuration-via-oauth2) need to update their error handling to correctly handle configuration when the internet is down.
8+
9+
Currently integrations using configuration via OAuth2 call `config_entry_oauth2_flow.async_get_config_entry_implementation` in `async_setup_entry` in their `__init__.py`. Previously when there was no network, this would raise `ValueError: Implementation not available`, which was a non-retryable error, resulting in the integration needing to be manually reconfigured after internet was restored (see Issues [153956](https://github.com/home-assistant/core/issues/153956) and [144582](https://github.com/home-assistant/core/issues/144582)). [core PR 154579](https://github.com/home-assistant/core/pull/154579) added `config_entry_oauth2_flow.ImplementationUnavailableError` and raises it in `config_entry_oauth2_flow.async_get_config_entry_implementation` when OAuth2 configuration is unavailable because of missing internet. Integrations should catch this error and raise `ConfigEntryNotReady`.
10+
The changed behavior with the new exception will be released in 2025.12.
11+
12+
Here is an example of the migration,
13+
```diff
14+
- implementation = await async_get_config_entry_implementation(hass, entry)
15+
+ try:
16+
+ implementation = await async_get_config_entry_implementation(hass, entry)
17+
+ except ImplementationUnavailableError as err:
18+
+ raise ConfigEntryNotReady(
19+
+ "OAuth2 implementation temporarily unavailable, will retry"
20+
+ ) from err
21+
```
22+
23+
New integrations will find the correct `try` / `except` block generated by `python3 -m script.scaffold config_flow_oauth2`.

0 commit comments

Comments
 (0)