Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks for config entry state in async_config_entry_first_refresh #128148

Merged
merged 6 commits into from
Oct 16, 2024

Conversation

epenet
Copy link
Contributor

@epenet epenet commented Oct 11, 2024

Breaking change

Proposed change

It should not be possible to call async_config_entry_first_refresh if a config entry is not in SETUP_IN_PROGRESS.

If it is called after the entry has been setup, then ConfigEntryNotReady will be raised but not handled, and failures will not be logged. It could also then be called more than once - leading to multiple calls to async_setup

Needs:

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)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

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
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format 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.

To help with the load of incoming pull requests:

@epenet epenet changed the title 20241011-1128 Add checks for config entry state in async_config_entry_first_refresh Oct 11, 2024
@epenet epenet added the deprecation Indicates a breaking change to happen in the future label Oct 11, 2024
@gjohansson-ST
Copy link
Member

The PR description does not say why it should not be supported?

@epenet
Copy link
Contributor Author

epenet commented Oct 11, 2024

The PR description does not say why it should not be supported?

PR description updated.

If it is called after the entry has been setup, then ConfigEntryNotReady will be raised but not handled, and failures will not be logged. It could also then be called more than once - leading to multiple calls so async_setup

@epenet epenet marked this pull request as ready for review October 14, 2024 05:45
@epenet epenet requested a review from a team as a code owner October 14, 2024 05:45
@epenet epenet modified the milestone: 2024.11.0b0 Oct 14, 2024
entry = MockConfigEntry()
crd = get_crd(hass, DEFAULT_UPDATE_INTERVAL, entry)
crd.setup_method = AsyncMock()
with pytest.raises(
Copy link
Member

Choose a reason for hiding this comment

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

Should this have a test when it doesn't raise?

Copy link
Contributor Author

@epenet epenet Oct 14, 2024

Choose a reason for hiding this comment

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

Should this have a test when it doesn't raise?

We have already : test_async_config_entry_first_refresh_success just above

Copy link
Member

Choose a reason for hiding this comment

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

I mean more explicitly that this raises because it's not coming from an integration (same with above but the config entry state is then ok).
So should we also have a test when raised from an integration that it's only logging and not raising (as that is the intention)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok!
Test added

Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Makes sense, thanks, @epenet 👍

../Frenck

@frenck frenck merged commit e5a07da into home-assistant:dev Oct 16, 2024
45 checks passed
@epenet epenet deleted the 20241011-1128 branch October 16, 2024 12:07
@@ -18,6 +19,7 @@
async def test_coordinator_device_info(hass: HomeAssistant) -> None:
"""Test reporting device information from the coordinator."""
entry = create_mock_entry()
entry._async_set_state(hass, ConfigEntryState.SETUP_IN_PROGRESS, None)
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to refactor these tests to not depend on integration details like the coordinator since these tests pop up failing all the time when we refactor things in helpers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would be nice to refactor these tests to not depend on integration details like the coordinator since these tests pop up failing all the time when we refactor things in helpers.

First step: #128517 moves to runtime data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would be nice to refactor these tests to not depend on integration details like the coordinator since these tests pop up failing all the time when we refactor things in helpers.

First step: #128517 moves to runtime data

Second step: #128591 adds abstraction to the initialisation and device_registry tests

@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed core deprecation Indicates a breaking change to happen in the future Hacktoberfest small-pr PRs with less than 30 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants