Fix onboarding crash when area translations are missing#171533
Conversation
|
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
Fixes a KeyError during onboarding user creation when default area translation keys are missing, by adding a fallback mechanism.
Changes:
- Load English area translations during onboarding to use as a fallback for missing keys in the user’s selected language.
- Use safe lookup for area translation keys, falling back to English and then to the raw area key.
| # Create default areas using the users supplied language. | ||
| # Create default areas using the users supplied language, | ||
| # falling back to English for any missing keys. | ||
| english_translations = await async_get_translations( |
There was a problem hiding this comment.
In my opinion we should do this transparent in async_get_translations.
async_get_translations should always return all the keys. If a translation is missing in the given language we include the english one. So we don't need to implement the manual fallback on each call and fix the issues for all occurrences.
@frenck What do you think?
There was a problem hiding this comment.
how would we know that not all keys are there?
There was a problem hiding this comment.
Essentially load english, overwrite with the lanbguage in the same structure, but deep merging that isn't really efficient I would say.
There was a problem hiding this comment.
We already do that actually
https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/translation.py#L216-L217
There was a problem hiding this comment.
Hmmm so what the crap is going south here?
There was a problem hiding this comment.
it's reported against the dev branch. Maybe they didn't generate translations? They are auto-generated when you run script/setup, but this person might not have run that.
Proposed change
Fix a
KeyErrorcrash during onboarding when area translation keys are not available. This happens when running Home Assistant Core from a development install or when translation files are incomplete for a given language. The onboarding user creation step crashes because it uses direct dict access on translations that may not exist.Now fetches English translations as a fallback for any missing keys in the user's language, with the area key itself as a last resort.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: