Skip to content

Avoid crashing due to unexpected entity category#71346

Closed
elupus wants to merge 1 commit intohome-assistant:devfrom
elupus:fix/category
Closed

Avoid crashing due to unexpected entity category#71346
elupus wants to merge 1 commit intohome-assistant:devfrom
elupus:fix/category

Conversation

@elupus
Copy link
Copy Markdown
Contributor

@elupus elupus commented May 5, 2022

Proposed change

Avoid crashing load of entity registry due to unexpected enum value for disable_by and entity_category

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@elupus elupus added this to the 2022.5.1 milestone May 5, 2022
@elupus elupus requested a review from a team as a code owner May 5, 2022 13:47
@probot-home-assistant probot-home-assistant bot added bugfix core small-pr PRs with less than 30 lines. labels May 5, 2022
@frenck
Copy link
Copy Markdown
Member

frenck commented May 5, 2022

I'm not sure why this is needed? The system category was for internal use, documented as such and never used. How would this have caused issues?

try:
return cls(value)
except ValueError:
_LOGGER.warning("Ignoring unexpected value %s for enum %s", value, cls)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should just ignore every unknown value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking startup of home assistant due to a single errounous value here is not a good ide.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative would be to ignore the complete entity with bad data.

Copy link
Copy Markdown
Member

@frenck frenck May 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking startup of home assistant due to a single errounous value here is not a good ide.

There are thousands of ways custom integrations could break the registries 🤷

Have we pinpointed the root cause/code/integration?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we have two reported issues that i know of so far.


from .entity import EntityCategory # pylint: disable=import-outside-toplevel

def parse_enum(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not define that as inline function, let's place that as standalone function into that file

"entity_id": "test.no_name",
"platform": "super_platform",
"unique_id": "without-name",
"disabled_by": "ignored-invalid-disabled-by",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also test the logger message

@elupus
Copy link
Copy Markdown
Contributor Author

elupus commented May 5, 2022

Any entity registry stored that happened to have system as it's category. Could have been a custom component or anything that leaves it behind. Any time we end up removing any enums, we need to handle loading a store with enums not in the class.

@frenck
Copy link
Copy Markdown
Member

frenck commented May 5, 2022

Any entity registry stored that happened to have system as it's category.

Nothing should have been using that?

@balloob
Copy link
Copy Markdown
Member

balloob commented May 5, 2022

It was available for 2 (?) releases. Since we removed it, we should just guard for system and replace it with None while loading and print a warning whenever an entity is added that has system category.

@balloob balloob mentioned this pull request May 5, 2022
22 tasks
@balloob
Copy link
Copy Markdown
Member

balloob commented May 5, 2022

Here is a PR that just filters out system #71361

@elupus
Copy link
Copy Markdown
Contributor Author

elupus commented May 5, 2022

Fine by me. I'd rather see a robust solution that avoids crashing if at all possible, but that fixes the immediate issue.

@elupus elupus closed this May 5, 2022
@balloob
Copy link
Copy Markdown
Member

balloob commented May 5, 2022

Since we guard the data that enters into storage, we shouldn't have to guard for any other bad data

@github-actions github-actions bot locked and limited conversation to collaborators May 6, 2022
@elupus elupus deleted the fix/category branch May 9, 2022 20:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix cla-signed core small-pr PRs with less than 30 lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Removal of 'system' entity category causes crash due to existing entities in registry storage having that category.

5 participants