Skip to content

feat: Cleanup of stale sensor references#2106

Open
joshuaunity wants to merge 4 commits intomainfrom
feat/remove-stale-sensor-refs
Open

feat: Cleanup of stale sensor references#2106
joshuaunity wants to merge 4 commits intomainfrom
feat/remove-stale-sensor-refs

Conversation

@joshuaunity
Copy link
Copy Markdown
Contributor

@joshuaunity joshuaunity commented Apr 14, 2026

Description

This PR implements a cleanup feature used to clean up sensor references on delete. Now, if a sensor is deleted, all its references in flex-config and sensors_to_show are deleted as well.

Look & Feel

None

How to test

  1. Look for or intentionally add a sensor to any of the options (flex-config or sensors to show)
  2. Delete that sensor, and confirm that its references are cleared in any of the above options you placed it in.

Further Improvements

None

Related Items

This PR closes #2099

Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

…r deletion

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
@joshuaunity joshuaunity self-assigned this Apr 14, 2026
@joshuaunity joshuaunity added bug Something isn't working enhancement New feature or request labels Apr 14, 2026
@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community bot commented Apr 14, 2026

@joshuaunity joshuaunity changed the title feat: implement cleanup of stale sensor references in assets on senso… feat: Cleanup of stale sensor references Apr 14, 2026
@joshuaunity joshuaunity requested a review from nhoening April 14, 2026 10:32
Copy link
Copy Markdown
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

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

Two larger comments:

  • cleanup_sensor_references_in_assets() could be called from a more central place in data/services/sensors.oy, I believe we have a until function to delete sensors there, or not?
  • we can assume that postgres is used, so some code can go.

@joshuaunity
Copy link
Copy Markdown
Contributor Author

cleanup_sensor_references_in_assets() could be called from a more central place in data/services/sensors.oy, I believe we have a until function to delete sensors there, or not?

ill check

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
@joshuaunity
Copy link
Copy Markdown
Contributor Author

cleanup_sensor_references_in_assets() could be called from a more central place in data/services/sensors.py, I believe we have a until function to delete sensors there, or not?

from my checks, no place solely handles the deletion of sensors in data/services/sensors.py,

@nhoening
Copy link
Copy Markdown
Contributor

I see. I was thinking of services/generic_assets.py, where I refactored a bit a few months ago.
Let's also start doing this here. We can create a common delete_sensor() method and a create_sensor() method, which both do the same, also write the same audit log message. And of course add your new logic to the deletion one.

  • The CLI for deletion has a confirmation dialogue, that can stay there of course
  • I just saw the API endpoint for deleting a sensor is writing the same audit log entry twice - good time to fix that.

@nhoening nhoening added this to the 0.33.0 milestone Apr 14, 2026
@nhoening
Copy link
Copy Markdown
Contributor

@joshuaunity I just noticed that I had written the same problem into an issue before: #2062

There I also proposed the new service method. And Felix suggested to ceate audit logs when removing the references - that makes some sense, too.

…n for improved data integrity

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
…r improved traceability

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
@joshuaunity
Copy link
Copy Markdown
Contributor Author

@joshuaunity I just noticed that I had written the same problem into an issue before: #2062

There I also proposed the new service method. And Felix suggested to ceate audit logs when removing the references - that makes some sense, too.

Following up on this, there is now:

  1. A central delete_sensor
  2. Logging sensor cleanups

@joshuaunity joshuaunity requested a review from nhoening April 15, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleting sensors should also remove them from flex-config and sensors-to-show

2 participants