fix(reserves): remove orphan symmetries - #3366
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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) |
| 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(): |
Contributor
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix 2 issues: