-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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
Fix logic for purge of recorder runs #130378
Conversation
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Can you safely compare to .end even if it's not always present in the database record? Will it be set if a recorder_run is closed incorrectly? Answering my own question:
Thanks for the fix @emontnemery |
@RudolfRendier That's a good point, I wonder if the order here matters: def delete_recorder_runs_rows(
purge_before: datetime, current_run_id: int
) -> StatementLambdaElement:
"""Delete recorder_runs rows."""
return lambda_stmt(
lambda: delete(RecorderRuns)
.filter(RecorderRuns.end < purge_before)
.filter(RecorderRuns.run_id != current_run_id)
.execution_options(synchronize_session=False)
) I'm setting this to draft until I've had the time to take a closer look. |
As we are releasing the milestone today, I've removed this draft PR for now. |
Implementation updated to explicitly not consider unclosed recorder runs in purge.
|
Proposed change
Fix logic for purge of recorder runs to purge recorder runs which end before the purge date instead of purging runs which start before the purge data
Rationale:
Until fairly recently we did not use the existence of recorder runs as a shortcut to avoid searching for history events, so when we purged the recorder runs was not very important.
However, we do now because of #104724 and I think @RudolfRendier is right, we need to change the purging of recorder runs.
This was noticed in #123449
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: