Skip to content

fix(reserves): remove orphan symmetries - #3366

Merged
MartinBelthle merged 31 commits into
devfrom
fix/symmetries-automatic-deletion
Aug 24, 2026
Merged

fix(reserves): remove orphan symmetries#3366
MartinBelthle merged 31 commits into
devfrom
fix/symmetries-automatic-deletion

Conversation

@MartinBelthle

@MartinBelthle MartinBelthle commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Fix 2 issues:

  • When removing a thermal cluster, orphan symmetries were not removed for FS storage mode (same issue for sts)
  • When removing a certification, orphan symmetries were not removed for both storage modes (same issue for sts)

@MartinBelthle MartinBelthle self-assigned this Aug 20, 2026
@MartinBelthle
MartinBelthle marked this pull request as ready for review August 21, 2026 13:50
@MartinBelthle
MartinBelthle requested a review from a team August 21, 2026 13:50
@olivierPigeon-RTE
olivierPigeon-RTE requested a lite review from Copilot August 24, 2026 07:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes reserve-participation cleanup so that deleting a thermal cluster / ST-storage or removing certifications also removes now-orphaned reserve symmetries, across both filesystem- and database-backed studies.

Changes:

  • Ensures filesystem serialization drops symmetries that no longer have corresponding certifications, and updates delete flows to remove participation entries directly.
  • Refactors DB reserve certification/symmetry handling and adds cascade cleanup of orphan symmetries after certification updates.
  • Extends DAO tests to cover symmetry cleanup when deleting assets or clearing/removing certifications.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/study/dao/test_thermal_reserves_dao.py Adds coverage for symmetry cleanup when thermal certifications are removed/cleared.
tests/study/dao/test_st_storage_reserves_dao.py Adds coverage for symmetry cleanup when ST-storage certifications are removed/cleared or storages deleted.
antarest/study/storage/rawstudy/model/filesystem/config/reserve_participations.py Filters serialized symmetries to only those backed by certifications (prevents orphan symmetries in FS mode).
antarest/study/dao/file/file_study_thermal_dao.py Deletes thermal reserve participation entries directly on cluster deletion (FS mode cascade cleanup).
antarest/study/dao/file/file_study_st_storage_dao.py Deletes ST-storage reserve participation entries directly on storage deletion (FS mode cascade cleanup).
antarest/study/dao/database/database_thermal_dao.py Uses shared validate_areas_exist() for area validation in DB error handling.
antarest/study/dao/database/database_st_storage_dao.py Uses shared validate_areas_exist() for area validation in DB error handling.
antarest/study/dao/database/database_reserve_symmetries_dao.py Refactors symmetry persistence to use shared reserve-type utilities and avoids integrity checks on pure deletions.
antarest/study/dao/database/database_reserve_definition_dao.py Splits and reuses orphan-symmetry deletion helpers for thermal and ST-storage cases.
antarest/study/dao/database/database_reserve_certification_dao.py Refactors certification persistence and adds cascade deletion of orphan symmetries after certification updates.
antarest/study/dao/database/database_renewable_dao.py Uses shared validate_areas_exist() for area validation in DB error handling.
antarest/study/dao/database/common.py Introduces validate_areas_exist() and centralizes reserve-type DB table/row conversions.
antarest/study/dao/api/common.py Adjusts “empty symmetries” detection and extends cascade removal to support per-object reserve removals.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +142 to +153
# Clean orphan symmetries
for area_id, reserves_dict in old_certifications.items():
missing_reserves: dict[str, set[ReserveDefinitionId]] = {}
for reserve_id, v in old_certifications[area_id].items():
for object_id in v:
if object_id not in new_certifications.get(area_id, {}).get(reserve_id, {}):
missing_reserves.setdefault(object_id, set()).add(reserve_id)
if missing_reserves:
if reserve_type == ReserveObjectType.THERMAL:
self.get_impl().delete_orphan_thermal_symmetries(area_id, missing_reserves)
else:
self.get_impl().delete_orphan_st_storage_symmetries(area_id, missing_reserves)
Comment thread antarest/study/dao/database/database_reserve_certification_dao.py
for reserve_id, storage_dict in reserves_dict.items():
for storage_id, certification in storage_dict.items():
for area_id, reserves_dict in new_certifications.items():
for reserve_id, thermal_dict in reserves_dict.items():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this method is not specific to thermal cluster, I guess you mean area_asset_dict or asset_dict. Same thing for thermal_id below

@MartinBelthle
MartinBelthle merged commit 4c03a57 into dev Aug 24, 2026
11 of 12 checks passed
@MartinBelthle
MartinBelthle deleted the fix/symmetries-automatic-deletion branch August 24, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants