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

Prevent async_create_entry from reauth/reconfigure flows #127527

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

epenet
Copy link
Contributor

@epenet epenet commented Oct 4, 2024

Breaking change

Use of async_create_entry within reauth and reconfigure flow causes new config entries to be created.
If an existing entry exists with the same unique_id, it will also cause the previous entry to be removed.

This invalid use of async_create_entry will be blocked from 2025.11.
Please refactor to use async_update_reload_and_abort or async_abort with a valid reason (eg. reauth_successful, reconfigure_successful, ...)

Proposed change

Tests have been added to highlight the behavior.

Sample run raising ValueError on core: https://github.com/home-assistant/core/actions/runs/11176114641

Violations fixed in:

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:

@home-assistant home-assistant bot added cla-signed core deprecation Indicates a breaking change to happen in the future Hacktoberfest small-pr PRs with less than 30 lines. labels Oct 4, 2024
@epenet epenet marked this pull request as ready for review October 4, 2024 09:07
@epenet epenet requested a review from a team as a code owner October 4, 2024 09:07
Comment on lines 2718 to 2719
"Detected %s config flow using `async_create_entry`, which "
"can cause unexpected behavior and will stop working in %s. "
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should not say "can cause unexpected behavior", I think we should say we want reconfigure and reauth flows to update an existing entry and then abort, not create a new entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Message updated

@emontnemery
Copy link
Contributor

We should update developer documentation to explain reconfigure and reauth flows are expected to update an existing entry and then abort:

@epenet
Copy link
Contributor Author

epenet commented Oct 4, 2024

We should update developer documentation to explain reconfigure and reauth flows are expected to update an existing entry and then abort:

I created a docs PR home-assistant/developers.home-assistant#2352

I have also adjusted the error message and the PR description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.

2 participants