Skip to content

Abort reauth flows on config entry reload #140931

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

Merged
merged 11 commits into from
Apr 10, 2025
Merged

Conversation

emontnemery
Copy link
Contributor

@emontnemery emontnemery commented Mar 19, 2025

Proposed change

Abort reauth flows on config entry reload

Background here: #140723 (comment)

Needs #142079

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:
  • Link to developer documentation pull request:
  • Link to frontend 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:

@emontnemery emontnemery requested a review from a team as a code owner March 19, 2025 13:42
@emontnemery emontnemery marked this pull request as draft March 19, 2025 15:29
@emontnemery
Copy link
Contributor Author

Tests fail because the reauth flow is now aborted early when reauth calls async_update_reload_and_abort

@emontnemery
Copy link
Contributor Author

emontnemery commented Mar 20, 2025

TODO: Add a test to assert we don't cancel reauth when reload is triggered by a reauth flow

This is no longer relevant

@emontnemery emontnemery force-pushed the abort_reauth_on_reload branch from 722d445 to 807ce27 Compare March 25, 2025 08:41
@bdraco bdraco self-requested a review March 25, 2025 16:27
Comment on lines 235 to 257
async def test_create_aborted_flow(manager: MockFlowManager) -> None:
"""Test return create_entry from aborted flow."""

@manager.mock_reg_handler("test")
class TestFlow(data_entry_flow.FlowHandler):
VERSION = 5

async def async_step_init(self, user_input=None):
manager.async_abort(self.flow_id)
return self.async_create_entry(title="Test Title", data="Test Data")

with pytest.raises(data_entry_flow.UnknownFlow):
await manager.async_init("test")
assert len(manager.async_progress()) == 0

# The entry is created even if the flow is aborted
assert len(manager.mock_created_entries) == 1

entry = manager.mock_created_entries[0]
assert entry["handler"] == "test"
assert entry["title"] == "Test Title"
assert entry["data"] == "Test Data"
assert entry["source"] is None
Copy link
Contributor Author

@emontnemery emontnemery Apr 3, 2025

Choose a reason for hiding this comment

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

The behavior is quite illogical; an entry is created without checking if the flow still exists, but there's then an error.
The behavior is not changed by this PR, but I think we should look into changing it in a follow-up.

Copy link
Member

Choose a reason for hiding this comment

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

Would you please add a comment to this test explaining that.

@emontnemery emontnemery marked this pull request as ready for review April 3, 2025 05:43
@emontnemery emontnemery requested a review from rytilahti as a code owner April 3, 2025 05:43
@bdraco
Copy link
Member

bdraco commented Apr 3, 2025

Looks good. Let me put it on production and test as well

@bdraco
Copy link
Member

bdraco commented Apr 3, 2025

Core works as expected but the frontend doesn't handle this well

once its reloaded the flow in the ui is still pointing to the old flow
so when you click it it errors

reconfig

@emontnemery
Copy link
Contributor Author

emontnemery commented Apr 3, 2025

Core works as expected but the frontend doesn't handle this well

once its reloaded the flow in the ui is still pointing to the old flow so when you click it it errors

The bug is that frontend is not updated when the reauth flow is aborted on reload.

This shows the same behavior with kitchen_sink

stale_reauth_flow_after_reload.mp4

@emontnemery
Copy link
Contributor Author

This PR can be simplified a bit when #142138 is merged.
I suggest we merge that PR first.

@emontnemery emontnemery marked this pull request as draft April 9, 2025 13:33
@emontnemery emontnemery marked this pull request as ready for review April 9, 2025 17:38
@emontnemery
Copy link
Contributor Author

emontnemery commented Apr 9, 2025

The frontend issue should be fixed by home-assistant/frontend#24985

@emontnemery emontnemery merged commit cf63175 into dev Apr 10, 2025
43 of 44 checks passed
@emontnemery emontnemery deleted the abort_reauth_on_reload branch April 10, 2025 18:55
@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants