Skip to content

migrate limits in v2.37#63

Open
EtienneLt wants to merge 2 commits into
mainfrom
migrate-limits-v237
Open

migrate limits in v2.37#63
EtienneLt wants to merge 2 commits into
mainfrom
migrate-limits-v237

Conversation

@EtienneLt
Copy link
Copy Markdown
Contributor

PR Summary

Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
@EtienneLt EtienneLt self-assigned this May 19, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

Review Change Stack

Warning

Rate limit exceeded

@EtienneLt has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 55 minutes and 2 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 101d632e-ba69-4a3c-843b-59176e125947

📥 Commits

Reviewing files that changed from the base of the PR and between 40fda26 and 2daa9da.

📒 Files selected for processing (1)
  • scripts/migrate_v237_limits.py
📝 Walkthrough

Walkthrough

This PR adds a new V2.37 limits migration feature to the admin-tools repository. It introduces a new endpoint constant, a helper function for issuing HTTP PUT requests to that endpoint, and a standalone migration orchestration script that iterates through all networks and variants with environment checks, dry-run support, and error handling.

Changes

V2.37 Limits Migration

Layer / File(s) Summary
Migration endpoint constant
scripts/constant.py
New MIGRATE_V237_LIMITS constant defines the URL template for the /migration/v237limits/{networkId}/{variantNum} migration endpoint.
Migration helper function
scripts/functions/networks/networks.py
New migrate_v237_limits(network_id, variant_num) function wraps an HTTP PUT request to the migration endpoint and enforces error propagation.
Migration orchestration script
scripts/migrate_v237_limits.py
New standalone script orchestrates the migration: parses CLI --dry-run flag, validates server availability and retrieves platform configuration, iterates through all networks and variants calling the helper function, and tracks/logs successes and failures with detailed error reporting.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The pull request description contains only a placeholder comment with no substantive content describing the changes, objectives, or implementation details. Fill in the PR description with a summary of what was changed, why the migration is needed, and any important notes for reviewers.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'migrate limits in v2.37' directly aligns with the primary change: adding a migration mechanism for v2.37 limits across networks.
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.

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: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/functions/networks/networks.py`:
- Around line 33-35: The migrate_v237_limits function currently issues
requests.put without a timeout which can hang the migration loop; modify
migrate_v237_limits to pass an explicit timeout to requests.put (e.g.,
timeout=10 or a small configurable constant) so the call fails fast, and keep
the existing response.raise_for_status() behavior; reference the requests.put
call and constant.MIGRATE_V237_LIMITS when making this change and optionally
catch requests.exceptions.Timeout around the call if you want to log or retry
separately.

In `@scripts/migrate_v237_limits.py`:
- Line 58: The migration banner prints the wrong version; update the print call
in migrate_v237_limits.py that currently uses "V2.11 limits migration (dry-run="
+ str(dry_run) + ")" so it reflects the correct migration version for this
script (e.g., "V2.37 limits migration (dry-run=" + str(dry_run) + ")"), keeping
the dry_run variable interpolation unchanged to avoid altering behavior.
- Line 42: The preflight check uses sys.exit() which returns zero on failure;
update the failure path where
check_server_status(constant.NETWORK_STORE_SERVER_HOSTNAME) is False to exit
with a non-zero code (e.g., sys.exit(1)) and optionally emit an error message
before exiting so CI/batch runners treat the failure as an error; modify the
line referencing check_server_status and sys.exit() accordingly.
- Around line 24-31: The current parser.add_argument for "-n/--dry-run" uses
action="store_true" so dry_run becomes False by default; change the CLI so
dry_run defaults to True and the flag explicitly enables execution (e.g., add a
new flag like "--execute" / "-x" with action="store_true" or change to
"--no-dry-run" with action="store_true" and then set dry_run = not
args.execute/args.no_dry_run), update the dry_run assignment accordingly, and
update the help text on parser.add_argument and the description to state that
the script performs migration PUTs (not deletions) and that dry-run is the
default unless the execute/no-dry-run flag is provided.
- Around line 68-74: The except block in migrate_v237_limits() is too broad and
swallows programming errors; change the handler to only catch
requests.exceptions.RequestException (e.g., replace "except Exception as e:"
with "except requests.exceptions.RequestException as e:") so that network/HTTP
failures are logged for network (network['uuid']) and variant (variant['num'])
as currently done, including the response body when available, while allowing
non-request exceptions (KeyError, TypeError, etc.) to propagate and fail fast.
🪄 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: 3ecb39eb-20ba-48b8-8fc8-3517cb497ff1

📥 Commits

Reviewing files that changed from the base of the PR and between 3a93251 and 40fda26.

📒 Files selected for processing (3)
  • scripts/constant.py
  • scripts/functions/networks/networks.py
  • scripts/migrate_v237_limits.py

Comment on lines +33 to +35
def migrate_v237_limits(network_id, variant_num):
response = requests.put(constant.MIGRATE_V237_LIMITS.format(networkId=network_id, variantNum=variant_num))
response.raise_for_status()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

# Locate and examine the networks.py file
find . -path "*scripts/functions/networks/networks.py" -type f

Repository: gridsuite/admin-tools

Length of output: 106


🏁 Script executed:

# Show the content around lines 33-35
if [ -f "scripts/functions/networks/networks.py" ]; then
  cat -n "scripts/functions/networks/networks.py" | sed -n '25,45p'
fi

Repository: gridsuite/admin-tools

Length of output: 697


🏁 Script executed:

# Search for where migrate_v237_limits is called
rg "migrate_v237_limits" -n -B 2 -A 2

Repository: gridsuite/admin-tools

Length of output: 1293


🏁 Script executed:

# Check for timeout patterns in similar requests in the codebase
rg "requests\.(put|post|get|patch)" -A 2 | head -100

Repository: gridsuite/admin-tools

Length of output: 7742


🏁 Script executed:

# Look for timeout constants defined
rg "TIMEOUT|timeout" scripts/functions/networks/ -n

Repository: gridsuite/admin-tools

Length of output: 47


🏁 Script executed:

# Examine the migrate_v237_limits.py file to see the full loop context
cat -n "scripts/migrate_v237_limits.py" | sed -n '60,75p'

Repository: gridsuite/admin-tools

Length of output: 1082


🏁 Script executed:

# Check for any timeout configurations or constants
rg "timeout" -i --max-count 20

Repository: gridsuite/admin-tools

Length of output: 3227


🏁 Script executed:

# Check similar migration functions to see if any have timeouts
cat -n "scripts/functions/networks/networks.py" | head -40

Repository: gridsuite/admin-tools

Length of output: 1682


Add an explicit timeout to prevent indefinite blocking in the migration loop.

This function is called within a nested loop over all networks and variants. Without a timeout, a single hung HTTP request will stall the entire migration indefinitely. The fix is straightforward.

Suggested fix
 def migrate_v237_limits(network_id, variant_num):
-    response = requests.put(constant.MIGRATE_V237_LIMITS.format(networkId=network_id, variantNum=variant_num))
+    response = requests.put(
+        constant.MIGRATE_V237_LIMITS.format(networkId=network_id, variantNum=variant_num),
+        timeout=30,
+    )
     response.raise_for_status()
🧰 Tools
🪛 Ruff (0.15.13)

[error] 34-34: Probable use of requests call without timeout

(S113)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/functions/networks/networks.py` around lines 33 - 35, The
migrate_v237_limits function currently issues requests.put without a timeout
which can hang the migration loop; modify migrate_v237_limits to pass an
explicit timeout to requests.put (e.g., timeout=10 or a small configurable
constant) so the call fails fast, and keep the existing
response.raise_for_status() behavior; reference the requests.put call and
constant.MIGRATE_V237_LIMITS when making this change and optionally catch
requests.exceptions.Timeout around the call if you want to log or retry
separately.

Comment on lines +24 to +31
parser = argparse.ArgumentParser(description='Send requests to the gridsuite services to migrate V2.37 limits', )

parser.add_argument("-n", "--dry-run", help="test mode (default) will not execute any deletion request",
action="store_true")


args = parser.parse_args()
dry_run = args.dry_run
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Make dry-run the real default before this runs against all networks.

With action="store_true", running the script with no flags sets dry_run to False, so it will execute the migration even though the help text says dry-run is the default. The help text also mentions deletion requests, but this script issues migration PUTs.

Suggested fix
 parser = argparse.ArgumentParser(description='Send requests to the gridsuite services to migrate V2.37 limits', )
 
-parser.add_argument("-n", "--dry-run", help="test mode (default) will not execute any deletion request",
-                    action="store_true")
+parser.add_argument(
+    "-n",
+    "--dry-run",
+    dest="dry_run",
+    action="store_true",
+    default=True,
+    help="test mode (default) will not execute any migration request",
+)
+parser.add_argument(
+    "--execute",
+    dest="dry_run",
+    action="store_false",
+    help="apply the migration requests",
+)
 
 
 args = parser.parse_args()
 dry_run = args.dry_run
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/migrate_v237_limits.py` around lines 24 - 31, The current
parser.add_argument for "-n/--dry-run" uses action="store_true" so dry_run
becomes False by default; change the CLI so dry_run defaults to True and the
flag explicitly enables execution (e.g., add a new flag like "--execute" / "-x"
with action="store_true" or change to "--no-dry-run" with action="store_true"
and then set dry_run = not args.execute/args.no_dry_run), update the dry_run
assignment accordingly, and update the help text on parser.add_argument and the
description to state that the script performs migration PUTs (not deletions) and
that dry-run is the default unless the execute/no-dry-run flag is provided.

print("\n")

# Check network-store-server
if not check_server_status(constant.NETWORK_STORE_SERVER_HOSTNAME): sys.exit()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Exit non-zero when the preflight check fails.

A bare sys.exit() returns success here, so CI or batch runners can treat “network-store-server unavailable” as a successful migration run.

Suggested fix
-if not check_server_status(constant.NETWORK_STORE_SERVER_HOSTNAME): sys.exit()
+if not check_server_status(constant.NETWORK_STORE_SERVER_HOSTNAME):
+    sys.exit(1)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if not check_server_status(constant.NETWORK_STORE_SERVER_HOSTNAME): sys.exit()
if not check_server_status(constant.NETWORK_STORE_SERVER_HOSTNAME):
sys.exit(1)
🧰 Tools
🪛 Ruff (0.15.13)

[error] 42-42: Multiple statements on one line (colon)

(E701)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/migrate_v237_limits.py` at line 42, The preflight check uses
sys.exit() which returns zero on failure; update the failure path where
check_server_status(constant.NETWORK_STORE_SERVER_HOSTNAME) is False to exit
with a non-zero code (e.g., sys.exit(1)) and optionally emit an error message
before exiting so CI/batch runners treat the failure as an error; modify the
line referencing check_server_status and sys.exit() accordingly.

print("For a total of " + str(len(networks)) + " networks")
print("---------------------------------------------------------")

print("V2.11 limits migration (dry-run=" + str(dry_run) + ") in processing...")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix the migration banner version.

This still logs V2.11 limits migration, which is easy to confuse with the older migration during operations.

Suggested fix
-print("V2.11 limits migration (dry-run=" + str(dry_run) + ") in processing...")
+print("V2.37 limits migration (dry-run=" + str(dry_run) + ") in processing...")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
print("V2.11 limits migration (dry-run=" + str(dry_run) + ") in processing...")
print("V2.37 limits migration (dry-run=" + str(dry_run) + ") in processing...")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/migrate_v237_limits.py` at line 58, The migration banner prints the
wrong version; update the print call in migrate_v237_limits.py that currently
uses "V2.11 limits migration (dry-run=" + str(dry_run) + ")" so it reflects the
correct migration version for this script (e.g., "V2.37 limits migration
(dry-run=" + str(dry_run) + ")"), keeping the dry_run variable interpolation
unchanged to avoid altering behavior.

Comment on lines +68 to +74
except Exception as e:
failCount += 1
# print only str(e) instead of the full traceback because we call this method from a simple for loop script
tqdm.write("network " + network['uuid'] + ", variantNum " + str(variant['num']) + " => migration failed: "+ str(e))
if isinstance(e, requests.exceptions.RequestException) and e.response is not None:
tqdm.write("Response body: " + repr(e.response.text)) # repr for cheap escaping
tqdm.write("") # emtpy newline between errors for legibility
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

cat -n scripts/migrate_v237_limits.py | head -100

Repository: gridsuite/admin-tools

Length of output: 3740


🏁 Script executed:

find . -type f -name "*.py" | xargs grep -l "def migrate_v237_limits"

Repository: gridsuite/admin-tools

Length of output: 106


🏁 Script executed:

cat -n ./scripts/functions/networks/networks.py | head -200

Repository: gridsuite/admin-tools

Length of output: 1682


Narrow exception handling to requests failures only.

The migrate_v237_limits() function only raises requests.exceptions.RequestException and its subclasses (from requests.put() and response.raise_for_status()). Catching all Exception masks programming bugs (e.g., KeyError from malformed API data) that should fail fast rather than continue with partial migrations.

Suggested fix
-            except Exception as e:
+            except requests.exceptions.RequestException as e:
                 failCount += 1
                 # print only str(e) instead of the full traceback because we call this method from a simple for loop script
                 tqdm.write("network " + network['uuid'] + ", variantNum " + str(variant['num']) + " => migration failed: "+ str(e))
-                if isinstance(e, requests.exceptions.RequestException) and e.response is not None:
+                if e.response is not None:
                     tqdm.write("Response body: " + repr(e.response.text)) # repr for cheap escaping
                 tqdm.write("") # emtpy newline between errors for legibility
🧰 Tools
🪛 Ruff (0.15.13)

[warning] 68-68: Do not catch blind exception: Exception

(BLE001)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/migrate_v237_limits.py` around lines 68 - 74, The except block in
migrate_v237_limits() is too broad and swallows programming errors; change the
handler to only catch requests.exceptions.RequestException (e.g., replace
"except Exception as e:" with "except requests.exceptions.RequestException as
e:") so that network/HTTP failures are logged for network (network['uuid']) and
variant (variant['num']) as currently done, including the response body when
available, while allowing non-request exceptions (KeyError, TypeError, etc.) to
propagate and fail fast.

Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
36.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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