Fix For ghsa-rghg-q7wp-9767#8885
Conversation
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
📝 WalkthroughWalkthroughThe PR hardens dataset identifier handling in nnUNetV2Runner. It introduces Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Hi @garciadias please review this again, it's the same code you've approved elsewhere. |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
tests/integration/test_integration_nnunetv2_runner.py (1)
23-34:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winScope the logger suppression to this test class.
Line 33 mutates the runner logger at import time and never restores it, so unrelated tests in the same process lose warning output too. Patch it in
setUpClass/tearDownClassor in the specific tests that need it.🤖 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 `@tests/integration/test_integration_nnunetv2_runner.py` around lines 23 - 34, The global logger suppression call monai.apps.nnunet.nnunetv2_runner.logger.setLevel(logging.ERROR) is applied at import time and should be scoped to the test class; move this mutation into the test class lifecycle (e.g., setUpClass to save the original level and set ERROR, and tearDownClass to restore the saved level) or apply/reset inside individual tests that need it so unrelated tests are not affected; ensure you reference monai.apps.nnunet.nnunetv2_runner.logger and restore its original level when done.monai/apps/nnunet/nnunetv2_runner.py (1)
200-213:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftNormalize
dataset_name_or_idonce here.Line 204 accepts
"Dataset123", but Line 212 immediately doesint(self.dataset_name_or_id). That sends validDataset###inputs through the exception path, leavesself.dataset_nameasNone, and makes the new guards reject an input this constructor already accepted. The remainingint(self.dataset_name_or_id)call sites in this class have the same mismatch, so the new contract is only partially implemented.As per coding guidelines, "Examine code for logical error or inconsistencies, and suggest what may be changed to addressed these."
🤖 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 `@monai/apps/nnunet/nnunetv2_runner.py` around lines 200 - 213, The constructor normalizes dataset_name_or_id incorrectly by always calling int(self.dataset_name_or_id) which fails for valid non-numeric names like "Dataset123"; change the logic in the block referencing self.dataset_name_or_id and maybe_convert_to_dataset_name so that if self.dataset_name_or_id is purely numeric (e.g., str.isdigit() or re.fullmatch(r"\d+")), call maybe_convert_to_dataset_name(int(self.dataset_name_or_id)) and assign to self.dataset_name, otherwise treat the value as an explicit dataset name and set self.dataset_name = self.dataset_name_or_id (no int conversion); keep the same exception handling but ensure downstream code that currently calls int(...) on self.dataset_name_or_id is updated to only do that when the value is numeric.
🧹 Nitpick comments (1)
tests/integration/test_integration_nnunetv2_runner.py (1)
150-163: ⚡ Quick winExercise a path that reads
runner.dataset_name.The happy-path test only proves
__init__does not raise. It never touches a method that consumesself.dataset_name, so it would miss the valid-Dataset123regression where initialization succeeds but later guarded methods fail. Add an assertion onrunner.dataset_nameor call one guarded method with a prepared temp layout.As per coding guidelines, "Ensure new or modified definitions will be covered by existing or new unit tests."
🤖 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 `@tests/integration/test_integration_nnunetv2_runner.py` around lines 150 - 163, The tests currently only construct nnUNetV2Runner but never exercise the attribute or methods that consume dataset_name; update test_nnunetv2runner_good_dataset_name to either assert the created runner.dataset_name equals the expected value for each good_yml (or call a method that uses it, e.g., any method that references self.dataset_name) so the code path that reads/validates dataset_name is executed; reference the nnUNetV2Runner class and the dataset_name attribute in your change and similarly ensure test_nnunetv2runner_bad_dataset_name still triggers the ValueError path when using inject_yml.
🤖 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 `@tests/integration/test_integration_nnunetv2_runner.py`:
- Around line 110-148: The test YAMLs currently use relative paths (./data,
./work, ./nnUNet_raw, ./nnUNet_preprocessed, ./nnUNet_results) so
nnUNetV2Runner.__init__ creates directories in the repo cwd; update the YAML
strings (good_yml_content1, good_yml_content2, injecting_yml_content) to build
all generated paths inside the test temp dir (use self.test_dir) for keys
dataroot, datalist, work_dir, nnunet_raw, nnunet_preprocessed, and
nnunet_results so the runner creates those folders under self.test_dir and
tearDown can clean them up (also ensure the injected dataset_name_or_id test
keeps the path substitution to self.test_dir).
---
Outside diff comments:
In `@monai/apps/nnunet/nnunetv2_runner.py`:
- Around line 200-213: The constructor normalizes dataset_name_or_id incorrectly
by always calling int(self.dataset_name_or_id) which fails for valid non-numeric
names like "Dataset123"; change the logic in the block referencing
self.dataset_name_or_id and maybe_convert_to_dataset_name so that if
self.dataset_name_or_id is purely numeric (e.g., str.isdigit() or
re.fullmatch(r"\d+")), call
maybe_convert_to_dataset_name(int(self.dataset_name_or_id)) and assign to
self.dataset_name, otherwise treat the value as an explicit dataset name and set
self.dataset_name = self.dataset_name_or_id (no int conversion); keep the same
exception handling but ensure downstream code that currently calls int(...) on
self.dataset_name_or_id is updated to only do that when the value is numeric.
In `@tests/integration/test_integration_nnunetv2_runner.py`:
- Around line 23-34: The global logger suppression call
monai.apps.nnunet.nnunetv2_runner.logger.setLevel(logging.ERROR) is applied at
import time and should be scoped to the test class; move this mutation into the
test class lifecycle (e.g., setUpClass to save the original level and set ERROR,
and tearDownClass to restore the saved level) or apply/reset inside individual
tests that need it so unrelated tests are not affected; ensure you reference
monai.apps.nnunet.nnunetv2_runner.logger and restore its original level when
done.
---
Nitpick comments:
In `@tests/integration/test_integration_nnunetv2_runner.py`:
- Around line 150-163: The tests currently only construct nnUNetV2Runner but
never exercise the attribute or methods that consume dataset_name; update
test_nnunetv2runner_good_dataset_name to either assert the created
runner.dataset_name equals the expected value for each good_yml (or call a
method that uses it, e.g., any method that references self.dataset_name) so the
code path that reads/validates dataset_name is executed; reference the
nnUNetV2Runner class and the dataset_name attribute in your change and similarly
ensure test_nnunetv2runner_bad_dataset_name still triggers the ValueError path
when using inject_yml.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9e6b46ff-3d01-4d50-b1b1-3975cd0db459
📒 Files selected for processing (2)
monai/apps/nnunet/nnunetv2_runner.pytests/integration/test_integration_nnunetv2_runner.py
Fixes advisory ghsa-rghg-q7wp-9767.
Description
A few sentences describing the changes proposed in this pull request.
Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.