core icon indicating copy to clipboard operation
core copied to clipboard

Possible unexpected data loss using recorder.purge_entities from UI

Open roztobart opened this issue 1 year ago • 2 comments

The problem

recorder.purge_entities service called from UI allows for unintentional removal of states of all entities.

I want to purge entities for a random Device. I go to Developer Tools > Services, chose Recorder: Purge entities and pick up this Device in the blue Device picker.

Preview of the yaml created by UI:

service: recorder.purge_entities
data:
  domains: []
  entity_globs: []
  keep_days: 0
target:
  device_id: af176ba74178560e3328f5516c008e2a

I call the service expecting entities of only this Device to be purged. Instead all of my entities get purged, as it's described in docs https://www.home-assistant.io/integrations/recorder/#service-purge_entities:

Call the service recorder.purge_entities to start a task that purges events and states from the recorder database that match any of the specified entity_id, domains and entity_globs fields. Leaving all three parameters empty will result in all entities being selected for purging.

Also in docs:

Note: The entity_id is only optional when used in automations.yaml or scripts.yaml . When using the UI to call this service then it is mandatory to specify at least one entity_id using the Target Picker or via YAML mode.

So UI prevents me from purging all entities incidentally, unless I pick up a random Device (and leave Entity and Domains data fields empty expecting to purge all Entities and Domains but in the scope of this Device only). Then UI allows me to call recorder.purge_entities and unconsciously purge all entities.

I would expect either:

  1. specifying a Device purges entities of this Device only or requires me to pick up specific entities or
  2. specifying a Device only without entities doesn't let me to call the service (and remove all of my entities).

Problem also discussed on forum https://community.home-assistant.io/t/recorder-purge-entities-removed-entities-i-didnt-want-to-be-removed/658019

What version of Home Assistant Core has the issue?

2023.12.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

No response

Link to integration documentation on our website

https://www.home-assistant.io/integrations/recorder/#service-purge_entities

Diagnostics information

No response

Example YAML snippet

service: recorder.purge_entities
data:
  domains: []
  entity_globs: []
  keep_days: 0
target:
  device_id: af176ba74178560e3328f5516c008e2a

Anything in the logs that might be useful for us?

No response

Additional information

No response

roztobart avatar Dec 20 '23 18:12 roztobart

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (recorder) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of recorder can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign recorder Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


recorder documentation recorder source (message by IssueLinks)

home-assistant[bot] avatar Dec 20 '23 18:12 home-assistant[bot]

The same thing just happened to me. This should be considered as a bug. I selected a device and all entities got purged...

cypherbits avatar Feb 08 '24 19:02 cypherbits

I believe the same just happened to me too. I thought using the UI would give the intended functionality, but instead it looks like all sensor data is gone after running with some entities selected. Very frustrating.

Home assistant yellow, core: 2024.2.2

Recorder settings: image

ctag avatar Feb 17 '24 23:02 ctag

When will this be fixed? I love the new UI features and the performance bdraco is doing but some basic bug fixes like this one would be good too...

cypherbits avatar Apr 08 '24 11:04 cypherbits