Avoid exception when loading translation file for unloaded module#15765
Avoid exception when loading translation file for unloaded module#15765awarecan wants to merge 3 commits intohome-assistant:devfrom
Conversation
homeassistant/helpers/translation.py
Outdated
| name = component | ||
|
|
||
| module = get_component(hass, component) | ||
| if module is None: |
There was a problem hiding this comment.
This makes no sense. get_component is not about things not being setup. It's about loading the component from file, either from your custom components dir or from built-in.
There was a problem hiding this comment.
Alright, you are forcing me to fix the root cause. Got it.
homeassistant/util/json.py
Outdated
|
|
||
| Defaults to returning empty dict if file is not found. | ||
| """ | ||
| if filename is None: |
There was a problem hiding this comment.
This is also not good. We should fail. This code should never be called if filename is None.
We should write code that doesn't handle "bad" inputs and tries to fix them. Raise errors instead. The moment we fix them, that function will need to keep fixing it forever, even if other things get added to the function that would allow the previously bad input. The previously bad input expects to be "changed" or else bugs in other code happen.
|
I changed anther way to fix issue, but I am not sure I am doing right thing, the loader has pretty complex logic. Anyway, I got better result, even the nest component which has been failed during setup still get translation file loaded now. |
| try: | ||
| return hass.data[DATA_KEY][comp_or_platform] # type: ignore | ||
| comp = hass.data[DATA_KEY][comp_or_platform] # type: ignore | ||
| if comp is not None: |
There was a problem hiding this comment.
Only place used loader.set_component method. Is that a legacy code?
There was a problem hiding this comment.
That happens if a component is not correctly coded, we don't have such components in our code base. It's only when people are having badly written custom components, hence the warning.
|
Root cause: home-assistant/architecture#52 |
|
I think you're misunderstanding the role of If you are having an import error, it means that you probably have a custom component and something is off. |
|
Aha, that is so tricky. Lesson learned. Closed this PR. |

Description:
There is a unhandled exception thrown if user navigate to config/integrations page in certain condition.
In my case, I disabled nest component in configuration.yaml, but didn't remove config entry from config, so it will cause nest component not loaded correctly. I am sure there may have other reason some module cannot be loaded correctly. In such scenario, all translation will be lost, screenshot likes
After this PR, only nest related translation will be lost, screenshot likes
Related issue (if applicable): fixes #
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf the code does not interact with devices: