Skip to content

Add pre-checks for temporary limit modifications#186

Open
flomillot wants to merge 8 commits intomainfrom
temporary-limit-modification-checks
Open

Add pre-checks for temporary limit modifications#186
flomillot wants to merge 8 commits intomainfrom
temporary-limit-modification-checks

Conversation

@flomillot
Copy link
Copy Markdown
Contributor

@flomillot flomillot commented Apr 23, 2026

Summary

  • Emit a warning and skip the modification when ADD is requested without a name, or when DELETE/MODIFY is requested without a name or acceptable duration (new preModificationCheck method).
  • When the OLG modification type is not MODIFY and the temporary limit modification type is not ADD, force the temporary limit modification type to ADD and log a detail report so the correction is traceable.
  • Expose a setter on CurrentTemporaryLimitModificationInfos to allow the modification type to be rewritten.
  • Fix the conditions about name comparison and add corresponding unit tests.

Emit a warning and skip the modification when ADD is requested without a
name, or when DELETE/MODIFY is requested without a name or acceptable
duration.

When the OLG modification type is not MODIFY and the temporary limit
modification type is not ADD, force the temporary limit modification
type to ADD and log a detail report to make the correction explicit.

Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds Lombok setters to a DTO and changes temporary-limit processing: validates required lookup fields, normalizes some per-row modification types to ADD, adds batch-aware duplicate detection/skipping, tightens deletion/matching/update semantics, adds report messages, and extends tests covering these behaviors.

Changes

Cohort / File(s) Summary
DTO
src/main/java/org/gridsuite/modification/dto/CurrentTemporaryLimitModificationInfos.java
Added Lombok @Setter to generate setters alongside existing getters.
Operational limits modification logic
src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java
Added per-row validation to skip entries missing name or acceptableDuration (logs temporaryLimitsMissingInfo); normalizes per-row modification type to ADD when OLG-level type disallows others (logs temporaryLimitsWrongModification); introduced batch-aware duplicate detection to skip conflicting ADD/MODIFY/MODIFY_OR_ADD rows (logs temporaryLimitsDuplicate) while allowing conflicts resolved by deletions in the same batch; refactored matching/deletion and update semantics (name/value handling and removal of prior invalidation behavior).
Reporting messages
src/main/resources/org/gridsuite/modification/reports.properties
Added message keys: network.modification.temporaryLimitsMissingInfo, network.modification.temporaryLimitsDuplicate, and network.modification.temporaryLimitsWrongModification.
Tests
src/test/java/org/gridsuite/modification/modifications/tabularmodifications/LimitSetModificationsTest.java
Extended tests: added many cases validating missing-field skips, forced-to-ADD normalization, duplicate detection (including same-batch delete/add edge cases), and REPLACE semantics; adjusted some existing test setups (name/value expectations).

Suggested reviewers

  • Mathieu-Deharbe
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add pre-checks for temporary limit modifications' accurately describes the main objective of the changeset: adding validation pre-checks for temporary limit modifications with warning/skip behavior and type constraints.
Description check ✅ Passed The description clearly outlines the key changes including pre-check validation logic, modification type forcing, setter exposure, and condition fixes, all of which align with the actual changeset modifications.
Docstring Coverage ✅ Passed Docstring coverage is 82.35% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@flomillot
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/test/java/org/gridsuite/modification/modifications/tabularmodifications/LimitSetModificationsTest.java (1)

272-280: ⚠️ Potential issue | 🟡 Minor

Stale comment: name is now required for MODIFY, update the inline comment.

The comment says // No name modification but name is now being set (it has to, since the new preModificationCheck rejects MODIFY without a name). Either remove the misleading comment or clarify that the name must be supplied even for a value-only modification.

✏️ Proposed fix
-                                                                        .name(toAttributeModification("name32", OperationType.SET)) // No name modification
+                                                                        .name(toAttributeModification("name32", OperationType.SET)) // Must supply existing name (required by preModificationCheck)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/org/gridsuite/modification/modifications/tabularmodifications/LimitSetModificationsTest.java`
around lines 272 - 280, The inline comment next to the name(...) call in the
CurrentTemporaryLimitModificationInfos.builder() block is stale because MODIFY
now requires a name; update or remove it: locate the
CurrentTemporaryLimitModificationInfos.builder() usage where modificationType is
TemporaryLimitModificationType.MODIFY and the name is set via
name(toAttributeModification("name32", OperationType.SET)), and either delete
the comment "// No name modification" or replace it with a note that name must
be provided for MODIFY (e.g., "name must be supplied for MODIFY per
preModificationCheck"), ensuring consistency with preModificationCheck behavior.
src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java (1)

551-563: ⚠️ Potential issue | 🟠 Major

Validate MODIFY_OR_ADD before name-based comparisons.

Lines 551 and 561–562 call limit.getName().getValue() unconditionally. preModificationCheck validates ADD/DELETE/MODIFY but leaves MODIFY_OR_ADD unvalidated when olgModifInfos.getModificationType() == MODIFY. The defensive conversion at lines 464–468 only applies when olgModifInfos != MODIFY, allowing a null name to reach getTemporaryLimitToModify, where lines 551 and 561–562 would trigger an NPE.

The test case at line 353 (LimitSetModificationsTest) demonstrates this scenario: olgModifInfos.getModificationType() == MODIFY paired with a MODIFY_OR_ADD limit. Add explicit validation for MODIFY_OR_ADD with name/duration checks equivalent to DELETE/MODIFY, or ensure the conversion logic covers all MODIFY_OR_ADD paths before calling getTemporaryLimitToModify.

Also note: line 561's duplicate-name check matches by equals including potential null values. An added limit with null name in the network (rare) could match a proposed null limit name.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java`
around lines 551 - 563, The code in OperationalLimitsGroupModification calls
limit.getName().getValue() in getTemporaryLimitToModify and in the
ADD-name-duplication check without handling MODIFY_OR_ADD, which can leave a
null name and cause NPEs; update preModificationCheck or the path that
converts/normalizes limits so MODIFY_OR_ADD is validated the same as
DELETE/MODIFY (i.e., require non-null name/duration) before calling
getTemporaryLimitToModify, or add defensive null checks inside
getTemporaryLimitToModify and the duplicate-name stream filter (e.g., verify
limit.getName()!=null and temporaryLimit.getName()!=null before equals) so
TemporaryLimitModificationType.MODIFY_OR_ADD/MODIFY paths cannot dereference a
null name.
🧹 Nitpick comments (2)
src/main/resources/org/gridsuite/modification/reports.properties (1)

311-314: Message keys and ${modificationType} placeholders align with the new report builders in OperationalLimitsGroupModification.preModificationCheck. LGTM.

Minor wording nit (optional): “Missing info (name or duration)” is reported also when both are missing — consider “Missing name and/or duration” for precision. Not blocking.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/resources/org/gridsuite/modification/reports.properties` around
lines 311 - 314, Update the user-facing message for the key
network.modification.temporaryLimitsMissingInfo to be more precise by changing
"Missing info (name or duration)" to "Missing name and/or duration"; keep the
${modificationType} placeholder and the rest of the message unchanged so it
still matches the usage in
OperationalLimitsGroupModification.preModificationCheck and other report
builders.
src/test/java/org/gridsuite/modification/modifications/tabularmodifications/LimitSetModificationsTest.java (1)

433-651: Good coverage of the new validation paths. Consider adding a MODIFY_OR_ADD with missing-name test.

Tests exercise ADD/DELETE/MODIFY missing-name and missing-duration paths plus the wrong-modification-type normalization, which matches the new preModificationCheck semantics. Given that MODIFY_OR_ADD is a valid per-limit modificationType (see testModifyOrAddNonExistentLimit), adding a test with modificationType=MODIFY_OR_ADD and name=null would expose the gap flagged in the main source comment.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/org/gridsuite/modification/modifications/tabularmodifications/LimitSetModificationsTest.java`
around lines 433 - 651, Add a test covering the missing-name case when a
per-limit modification uses TemporaryLimitModificationType.MODIFY_OR_ADD:
duplicate the pattern from testAddTemporaryLimitWithMissingName but set
CurrentTemporaryLimitModificationInfos.modificationType to
TemporaryLimitModificationType.MODIFY_OR_ADD and name to null, then apply
modificationInfos.toModification().apply(...), assert the temporary limit was
not added (assertNull on limits.getTemporaryLimit(duration)) and assert the same
log via assertLogMessageWithoutRank (use the "Missing name for temporary limit
to ADD: ignored" message and "network.modification.temporaryLimitsMissingName"
key) to verify MODIFY_OR_ADD follows the ADD missing-name validation path; place
the test alongside the other temporary-limit missing-info tests and reference
LimitSetsTabularModificationInfos, CurrentTemporaryLimitModificationInfos,
TemporaryLimitModificationType.MODIFY_OR_ADD, and assertLogMessageWithoutRank to
locate code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java`:
- Around line 463-473: The current logic in OperationalLimitsGroupModification
silently coerces a per-limit DELETE/MODIFY into an ADD when
olgModifInfos.getModificationType() !=
OperationalLimitsGroupModificationType.MODIFY: locate the block that checks
olgModifInfos.getModificationType() and limit.getModificationType() and either
(preferred) change it to skip the limit and log a warning when
limit.getModificationType() is DELETE or MODIFY (call addToLogsOnSide(...) with
TypedValue.WARN_SEVERITY and do not call limit.setModificationType(ADD)), or
(alternative) elevate the existing ReportNode severity from
TypedValue.DETAIL_SEVERITY to TypedValue.WARN_SEVERITY so the coercion is
visible; reference the symbols olgModifInfos, limit,
TemporaryLimitModificationType, OperationalLimitsGroupModificationType,
addToLogsOnSide, and ReportNode.newRootReportNode() when making the change.
- Around line 440-475: preModificationCheck fails to validate
TemporaryLimitModificationType.MODIFY_OR_ADD which can lead to a NPE later in
getTemporaryLimitToModify; update the validation so MODIFY_OR_ADD is treated
like MODIFY for required fields: include
TemporaryLimitModificationType.MODIFY_OR_ADD in the conditional that checks for
DELETE or MODIFY (the block using hasValue(limit.getName()) ||
hasValue(limit.getAcceptableDuration())) so that name and acceptableDuration are
validated for MODIFY_OR_ADD, and ensure the other branch that coerces non-MODIFY
OLGs to ADD (the block that checks olgModifInfos.getModificationType() !=
OperationalLimitsGroupModificationType.MODIFY && limit.getModificationType() !=
TemporaryLimitModificationType.ADD) still converts MODIFY_OR_ADD to ADD when
appropriate.

---

Outside diff comments:
In
`@src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java`:
- Around line 551-563: The code in OperationalLimitsGroupModification calls
limit.getName().getValue() in getTemporaryLimitToModify and in the
ADD-name-duplication check without handling MODIFY_OR_ADD, which can leave a
null name and cause NPEs; update preModificationCheck or the path that
converts/normalizes limits so MODIFY_OR_ADD is validated the same as
DELETE/MODIFY (i.e., require non-null name/duration) before calling
getTemporaryLimitToModify, or add defensive null checks inside
getTemporaryLimitToModify and the duplicate-name stream filter (e.g., verify
limit.getName()!=null and temporaryLimit.getName()!=null before equals) so
TemporaryLimitModificationType.MODIFY_OR_ADD/MODIFY paths cannot dereference a
null name.

In
`@src/test/java/org/gridsuite/modification/modifications/tabularmodifications/LimitSetModificationsTest.java`:
- Around line 272-280: The inline comment next to the name(...) call in the
CurrentTemporaryLimitModificationInfos.builder() block is stale because MODIFY
now requires a name; update or remove it: locate the
CurrentTemporaryLimitModificationInfos.builder() usage where modificationType is
TemporaryLimitModificationType.MODIFY and the name is set via
name(toAttributeModification("name32", OperationType.SET)), and either delete
the comment "// No name modification" or replace it with a note that name must
be provided for MODIFY (e.g., "name must be supplied for MODIFY per
preModificationCheck"), ensuring consistency with preModificationCheck behavior.

---

Nitpick comments:
In `@src/main/resources/org/gridsuite/modification/reports.properties`:
- Around line 311-314: Update the user-facing message for the key
network.modification.temporaryLimitsMissingInfo to be more precise by changing
"Missing info (name or duration)" to "Missing name and/or duration"; keep the
${modificationType} placeholder and the rest of the message unchanged so it
still matches the usage in
OperationalLimitsGroupModification.preModificationCheck and other report
builders.

In
`@src/test/java/org/gridsuite/modification/modifications/tabularmodifications/LimitSetModificationsTest.java`:
- Around line 433-651: Add a test covering the missing-name case when a
per-limit modification uses TemporaryLimitModificationType.MODIFY_OR_ADD:
duplicate the pattern from testAddTemporaryLimitWithMissingName but set
CurrentTemporaryLimitModificationInfos.modificationType to
TemporaryLimitModificationType.MODIFY_OR_ADD and name to null, then apply
modificationInfos.toModification().apply(...), assert the temporary limit was
not added (assertNull on limits.getTemporaryLimit(duration)) and assert the same
log via assertLogMessageWithoutRank (use the "Missing name for temporary limit
to ADD: ignored" message and "network.modification.temporaryLimitsMissingName"
key) to verify MODIFY_OR_ADD follows the ADD missing-name validation path; place
the test alongside the other temporary-limit missing-info tests and reference
LimitSetsTabularModificationInfos, CurrentTemporaryLimitModificationInfos,
TemporaryLimitModificationType.MODIFY_OR_ADD, and assertLogMessageWithoutRank to
locate code.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a45b8919-ecbb-4812-b535-04372f165021

📥 Commits

Reviewing files that changed from the base of the PR and between da6d00e and 028f2a7.

📒 Files selected for processing (4)
  • src/main/java/org/gridsuite/modification/dto/CurrentTemporaryLimitModificationInfos.java
  • src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java
  • src/main/resources/org/gridsuite/modification/reports.properties
  • src/test/java/org/gridsuite/modification/modifications/tabularmodifications/LimitSetModificationsTest.java

- Include REPLACE and MODIFY_OR_ADD in name validation for temporary limits.
- Update tests to cover new validation scenarios.

Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/test/java/org/gridsuite/modification/modifications/tabularmodifications/LimitSetModificationsTest.java (1)

431-910: Good coverage; suggest one extra scenario.

The new tests do a solid job pinning down missing-name/duration behavior for every per-limit op, the wrong-modification-type coercion, and the duplicate name/duration error paths.

Consider also adding a test for OLG MODIFY_OR_ADD against an existing group with a per-limit MODIFY (and a per-limit DELETE), to guard the case flagged in OperationalLimitsGroupModification.java lines 467–477 where the current coercion logic incorrectly rewrites the user’s intent.

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java`:
- Around line 467-477: The current coercion in
OperationalLimitsGroupModification unconditionally forces per-limit
modifications to ADD when olgModifInfos.getModificationType() !=
OperationalLimitsGroupModificationType.MODIFY, which incorrectly affects the
MODIFY_OR_ADD case for existing groups; change the condition to only coerce to
TemporaryLimitModificationType.ADD when the OLG mode is one that unconditionally
creates/replace the group (e.g., OperationalLimitsGroupModificationType.ADD or
REPLACE) rather than every non-MODIFY value, so update the if that calls
addToLogsOnSide(...) and
limit.setModificationType(TemporaryLimitModificationType.ADD) to explicitly
check for ADD/REPLACE modes; ensure related methods like
getTemporaryLimitToModify still operate correctly and add a test covering
MODIFY_OR_ADD against an existing group with per-limit MODIFY and DELETE to
prevent regressions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0c01f567-ed16-489e-b9d1-20cb3043ccb0

📥 Commits

Reviewing files that changed from the base of the PR and between 028f2a7 and 3aee33b.

📒 Files selected for processing (2)
  • src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java
  • src/test/java/org/gridsuite/modification/modifications/tabularmodifications/LimitSetModificationsTest.java

flomillot and others added 2 commits April 24, 2026 13:02
…s and update tests

Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
Unify pre-checks to require name and duration for all types, refuse
duplicates for ADD/MODIFY/MODIFY_OR_ADD, and make REPLACE take the
input as-is instead of preserving previous values. Refactor downstream
code now that duration is guaranteed non-null and extend the test
suite to cover all per-type cases.

Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java`:
- Around line 543-548: The current early returns after preModificationCheck(...)
and wouldCreateDuplicate(...) can cause modifyTemporaryLimits(...) to run its
group-level REPLACE cleanup even if no temporary-limit rows were accepted; fix
this by tracking and propagating an "acceptedChange" boolean from the per-row
processing (set true when a temporary-limit change is actually applied) and pass
it into modifyTemporaryLimits(...) so that the REPLACE cleanup (the branch that
suppresses unmodifiedTemporaryLimits) only runs when acceptedChange is true;
update the code paths around preModificationCheck(...),
wouldCreateDuplicate(...), and the caller of modifyTemporaryLimits(...) in
OperationalLimitsGroupModification to carry this flag through.
- Around line 604-607: The code currently only nulls limitToModify when the
incoming limit name differs, so a same-batch DELETE + ADD/MODIFY with the same
name still reuses the soon-to-be-deleted limit; change the conditional around
limitToModify (the block using limitToModify, limit.getName().getValue(),
isThisLimitDeleted, and currentLimitsInfos.getTemporaryLimits()) to treat the
limit as missing whenever isThisLimitDeleted(...) returns true (regardless of
name equality) — i.e., remove the name-equality guard and set limitToModify =
null when isThisLimitDeleted(currentLimitsInfos.getTemporaryLimits(),
limitAcceptableDuration) is true so the incoming ADD/MODIFY will not reuse a
limit scheduled for deletion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ca5be9a7-8d71-48d1-a2f4-3180b696aca6

📥 Commits

Reviewing files that changed from the base of the PR and between 3aee33b and b5381a1.

📒 Files selected for processing (3)
  • src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java
  • src/main/resources/org/gridsuite/modification/reports.properties
  • src/test/java/org/gridsuite/modification/modifications/tabularmodifications/LimitSetModificationsTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/resources/org/gridsuite/modification/reports.properties

- Improve name and duration validation logic for temporary limits.
- Simplify value assignment logic in REPLACE and MODIFY scenarios.
- Update and extend test cases to cover new validation conditions.

Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java (1)

604-607: ⚠️ Potential issue | 🟠 Major

Deleted durations are still reused when the re-added name matches.

After DELETE(duration=D, name=N), a later ADD/MODIFY for the same duration and same name keeps limitToModify non-null here, so the code falls into modifyTemporaryLimit(...) and can reuse stale fields from the deleted limit instead of treating D as free. The deleted-in-batch check should null out limitToModify for any non-DELETE operation, regardless of name equality. Please add a regression next to testAddTemporaryLimitConflictingWithDeletedInSameBatchSucceeds for the same-name case as well.

🩹 Proposed fix
-        if (limitToModify != null
-                && !limitToModify.getName().equals(limit.getName().getValue())
-                && isThisLimitDeleted(currentLimitsInfos.getTemporaryLimits(), limitAcceptableDuration)) {
+        if (limitToModify != null
+                && limit.getModificationType() != TemporaryLimitModificationType.DELETE
+                && isThisLimitDeleted(currentLimitsInfos.getTemporaryLimits(), limitAcceptableDuration)) {
             limitToModify = null;
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java`
around lines 604 - 607, The code keeps limitToModify non-null for a later
ADD/MODIFY that reuses the same name as a DELETE in the same batch, causing
stale fields to be reused; update the logic in
OperationalLimitsGroupModification so that whenever the current operation is not
a DELETE and isThisLimitDeleted(currentLimitsInfos.getTemporaryLimits(),
limitAcceptableDuration) returns true you explicitly set limitToModify = null
(so modifyTemporaryLimit(...) is not used and the duration is treated free), and
add a regression test next to
testAddTemporaryLimitConflictingWithDeletedInSameBatchSucceeds that covers the
same-duration same-name re-add case to ensure deleted durations are not reused.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java`:
- Around line 473-525: The duplicate check in wouldCreateDuplicate(...)
currently only inspects the immutable networkCurrentLimits snapshot (and returns
false when networkCurrentLimits is null), so it misses duplicates introduced
earlier in the same request; change the check to use a mutable working set
seeded from networkCurrentLimits (or an empty LoadingLimits if
networkCurrentLimits is null) and then consult that working set instead of
networkCurrentLimits when computing existingByDuration/existingByName; after a
row is accepted elsewhere in the flow, update that working set
(add/modify/remove entries) so subsequent calls to wouldCreateDuplicate see
prior accepted rows; keep existing behavior around isThisLimitDeleted(...) and
preserve log creation via addToLogsOnSide(...) and ReportNode.

---

Duplicate comments:
In
`@src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java`:
- Around line 604-607: The code keeps limitToModify non-null for a later
ADD/MODIFY that reuses the same name as a DELETE in the same batch, causing
stale fields to be reused; update the logic in
OperationalLimitsGroupModification so that whenever the current operation is not
a DELETE and isThisLimitDeleted(currentLimitsInfos.getTemporaryLimits(),
limitAcceptableDuration) returns true you explicitly set limitToModify = null
(so modifyTemporaryLimit(...) is not used and the duration is treated free), and
add a regression test next to
testAddTemporaryLimitConflictingWithDeletedInSameBatchSucceeds that covers the
same-duration same-name re-add case to ensure deleted durations are not reused.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bff42087-3ae4-439a-b2fd-3e99560556bb

📥 Commits

Reviewing files that changed from the base of the PR and between b5381a1 and 915c1dd.

📒 Files selected for processing (2)
  • src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java
  • src/test/java/org/gridsuite/modification/modifications/tabularmodifications/LimitSetModificationsTest.java

- Introduce a working set for temporary limits during batch processing.
- Refactor duplicate detection to handle in-batch conflicts.
- Update tests to validate in-batch duplicate rejection for ADD operations.

Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java (1)

618-621: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Same-name delete+add still reuses the deleted snapshot.

This is the same edge case previously flagged: when a later ADD/MODIFY targets a duration deleted earlier in the batch with the same name, the name check keeps limitToModify non-null, so the code goes down the modify path instead of treating the slot as free. That can preserve the old value when the incoming row leaves value unset.

🩹 Proposed fix
         if (limitToModify != null
-                && !limitToModify.getName().equals(limit.getName().getValue())
+                && limit.getModificationType() != TemporaryLimitModificationType.DELETE
                 && isThisLimitDeleted(currentLimitsInfos.getTemporaryLimits(), limitAcceptableDuration)) {
             limitToModify = null;
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java`
around lines 618 - 621, The code in OperationalLimitsGroupModification that
decides whether to reuse an existing snapshot (uses limitToModify and the name
comparison) misses the case where a slot was deleted earlier in the same batch
but the incoming row uses the same name, so it incorrectly follows the modify
path; change the logic so that if
isThisLimitDeleted(currentLimitsInfos.getTemporaryLimits(),
limitAcceptableDuration) is true for the target duration you always treat the
slot as missing (set/keep limitToModify null) regardless of the name comparison
— i.e., detect the deletion first (or add an explicit check) and null out
limitToModify when the temporary limits indicate a prior deletion, referencing
limitToModify, isThisLimitDeleted(...), currentLimitsInfos.getTemporaryLimits(),
limitAcceptableDuration, and limit.getName().getValue() to locate and fix the
branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java`:
- Around line 605-609: The method isThisLimitDeleted(...) currently treats any
DELETE row with an acceptableDuration as effective even if that DELETE would be
ignored earlier due to a missing name; update the predicate in
isThisLimitDeleted to only consider DELETE entries that have a valid name (e.g.,
add hasValue(temporaryLimit.getName()) or equivalent) so DELETE rows that would
be skipped by preModificationCheck(...) are ignored here too; locate the stream
in isThisLimitDeleted and add the name presence check alongside the existing
modificationType and acceptableDuration checks.

---

Duplicate comments:
In
`@src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java`:
- Around line 618-621: The code in OperationalLimitsGroupModification that
decides whether to reuse an existing snapshot (uses limitToModify and the name
comparison) misses the case where a slot was deleted earlier in the same batch
but the incoming row uses the same name, so it incorrectly follows the modify
path; change the logic so that if
isThisLimitDeleted(currentLimitsInfos.getTemporaryLimits(),
limitAcceptableDuration) is true for the target duration you always treat the
slot as missing (set/keep limitToModify null) regardless of the name comparison
— i.e., detect the deletion first (or add an explicit check) and null out
limitToModify when the temporary limits indicate a prior deletion, referencing
limitToModify, isThisLimitDeleted(...), currentLimitsInfos.getTemporaryLimits(),
limitAcceptableDuration, and limit.getName().getValue() to locate and fix the
branch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7313de91-cecb-4a43-9002-1c1aaff7368e

📥 Commits

Reviewing files that changed from the base of the PR and between 915c1dd and dfd231c.

📒 Files selected for processing (2)
  • src/main/java/org/gridsuite/modification/modifications/olg/OperationalLimitsGroupModification.java
  • src/test/java/org/gridsuite/modification/modifications/tabularmodifications/LimitSetModificationsTest.java

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant