fix: regression in dynamic resource handling#4038
fix: regression in dynamic resource handling#4038johanneskoester merged 8 commits intosnakemake:mainfrom
Conversation
Expressions referencing input.size_mb in --set-resources or --default-resources crash with ResourceConversionError when input files don't exist yet. The wrapped evaluator now passes TBDString through instead of requiring a numeric result, matching the convention in Resource.evaluate().
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughShort-circuits Resource._wrap_evaluator: when the underlying evaluator returns a TBDString, the value is returned immediately without type-checking or unit conversion, preserving unevaluated placeholder values. Also adds a test case and a minimal Snakefile to cover dynamic resource evaluation. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/tests.py`:
- Around line 2295-2300: The test test_issue_3970 passes a shellcmd string with
POSIX single quotes that break on Windows; update the shellcmd argument in the
run(...) call so the outer Python string uses single quotes and the inner CLI
expression uses double quotes (i.e., shellcmd="snakemake --default-resources
\"mem_mb=3*1024+input.size_mb\"") so both POSIX shells and cmd.exe receive the
expression correctly; locate the test by the function name test_issue_3970 and
the run(...) invocation that uses dpath("test_issue3970") to make the change.
| def test_issue_3970(): | ||
| run( | ||
| dpath("test_issue3970"), | ||
| shellcmd="snakemake --default-resources 'mem_mb=3*1024+input.size_mb'", | ||
| check_results=False, | ||
| ) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's find and verify the file location
find . -name "tests.py" -type f | head -20Repository: snakemake/snakemake
Length of output: 79
🏁 Script executed:
# Read the specific lines mentioned in the review
if [ -f "tests/tests.py" ]; then
sed -n '2290,2305p' tests/tests.py
fiRepository: snakemake/snakemake
Length of output: 435
🏁 Script executed:
# Look for similar test patterns and `@skip_on_windows` decorators
rg "@skip_on_windows" tests/tests.py -B 5 -A 5 | head -100Repository: snakemake/snakemake
Length of output: 2287
🏁 Script executed:
# Search for other shellcmd patterns in the test file to understand quoting conventions
rg 'shellcmd=' tests/tests.py | head -30Repository: snakemake/snakemake
Length of output: 2252
🏁 Script executed:
# Find test_issue3970 directory
find . -type d -name "*issue3970*" -o -name "*issue_3970*"Repository: snakemake/snakemake
Length of output: 85
🏁 Script executed:
# Search for any comments or documentation about issue 3970
rg "3970" --type-list | head -5
rg "3970" . --type py -B 2 -A 2 | head -50Repository: snakemake/snakemake
Length of output: 764
🏁 Script executed:
# Check if there are any platform-specific considerations in the test configuration
rg "test_issue3970" . -B 5 -A 5Repository: snakemake/snakemake
Length of output: 463
🏁 Script executed:
# List contents of test_issue3970 directory
ls -la tests/test_issue3970/
cat tests/test_issue3970/Snakefile 2>/dev/null || echo "No Snakefile found"
find tests/test_issue3970 -type f | xargs head -50Repository: snakemake/snakemake
Length of output: 707
🏁 Script executed:
# Check the git history or any PR that introduced this test
git log --oneline --all -- "*issue3970*" 2>/dev/null | head -20Repository: snakemake/snakemake
Length of output: 111
🏁 Script executed:
# Search for related issue documentation in the repository
find . -name "*.md" -o -name "*.rst" | xargs grep -l "3970" 2>/dev/nullRepository: snakemake/snakemake
Length of output: 47
Use cross-platform quoting for the CLI expression.
Line 2298 uses POSIX-style single quotes, which cmd.exe does not treat as special characters and will pass literally to the invoked command. This causes the test to fail on Windows before it exercises the dynamic default resources feature. Swap the quote styles: use single quotes for the Python string and double quotes for the shell expression, so the quotes are properly removed on both POSIX shells and Windows cmd.exe.
Suggested fix
def test_issue_3970():
run(
dpath("test_issue3970"),
- shellcmd="snakemake --default-resources 'mem_mb=3*1024+input.size_mb'",
+ shellcmd='snakemake --default-resources "mem_mb=3*1024+input.size_mb"',
check_results=False,
)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@tests/tests.py` around lines 2295 - 2300, The test test_issue_3970 passes a
shellcmd string with POSIX single quotes that break on Windows; update the
shellcmd argument in the run(...) call so the outer Python string uses single
quotes and the inner CLI expression uses double quotes (i.e.,
shellcmd="snakemake --default-resources \"mem_mb=3*1024+input.size_mb\"") so
both POSIX shells and cmd.exe receive the expression correctly; locate the test
by the function name test_issue_3970 and the run(...) invocation that uses
dpath("test_issue3970") to make the change.
|
Needs a |
🤖 I have created a release *beep* *boop* --- ## [9.17.0](v9.16.3...v9.17.0) (2026-03-13) ### Features * Allow storing snakemake metadata in files or databases ([#4012](#4012)) ([dd75f31](dd75f31)) * Allow to specify comparison command per-unit test ([#3956](#3956)) ([b88171c](b88171c)) * job table orderd topological when run is started ([#4018](#4018)) ([75cf506](75cf506)) * lambda functions for priority in rules ([#3253](#3253)) ([d2aa226](d2aa226)) * Make on... directive of modules accessible ([#4050](#4050)) ([e9f2e1c](e9f2e1c)) ### Bug Fixes * adjust conda tests to not fail on apple silicon; fix [#4040](#4040) ([#4049](#4049)) ([f5b0142](f5b0142)) * allow "--containerize apptainer" to output apptainer format instead of dockerfile ([#4030](#4030)) ([f5cac30](f5cac30)) * apptainer command not recognized when singularity is absent ([#4010](#4010)) ([b8162e2](b8162e2)) * capture stderr when tests fail ([#3995](#3995)) ([97d74ba](97d74ba)) * **docs:** make Data-dependent conditional execution a complete example ([#4043](#4043)) ([3a1d7f2](3a1d7f2)) * don't build the DAG when running unlock. Fixes [#4000](#4000) and [#198](#198) ([#4007](#4007)) ([acf79fd](acf79fd)) * Ensure pixi tasks may be run as advertised ([#4046](#4046)) ([88253c2](88253c2)) * fix checkpoint handling corner cases ([#3870](#3870) and [#3559](#3559)) ([#4015](#4015)) ([63f4257](63f4257)) * issue 3642 ([#4054](#4054)) ([76e6fc2](76e6fc2)) * issue 3815 ([#4026](#4026)) ([b0eec96](b0eec96)) * logging None in shellcmd context causes error ([#4064](#4064)) ([d0652cd](d0652cd)) * lookup function returns default value for empty DataFrame queries ([#4056](#4056)) ([f71de97](f71de97)) * make `cache: omit-software` a rule specific property ([#4085](#4085)) ([034a9e7](034a9e7)) * reduce number of tests leaving temporary files behind ([#4033](#4033)) ([a3a1c97](a3a1c97)) * regression in dynamic resource handling ([#4038](#4038)) ([f2c554a](f2c554a)) * somewhat shorter announce message ([#4080](#4080)) ([57efc71](57efc71)) ### Performance Improvements * switch reretry with tenacity; decouple container classes (with Python 3.7 compat for old scripts) from rest of the codebase (enabling moving to newer python versions) ([#4032](#4032)) ([ffb19e7](ffb19e7)) ### Documentation * Add AI-assisted contributions policy to contributing guidelines ([#4051](#4051)) ([dd70526](dd70526)) * **codebase:** Update & simplify plugin architecture section ([#4052](#4052)) ([176cf63](176cf63)) * Correct workflow.source_path() description in documentation ([#4036](#4036)) ([45883c5](45883c5)) * fixed wrong code example for collect() function ([#4037](#4037)) ([5c85ed8](5c85ed8)) * Minor docs improvements ([#4089](#4089)) ([29ea226](29ea226)) * switch to sphinx_design for tabs ([#3976](#3976)) ([9674614](9674614)) * typo in the migration table breaking a pip install command ([#4024](#4024)) ([66f9dda](66f9dda)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Fixes dynamic resource parsing regression introduced in #3421. Closes #3970
QC
docs/) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake).Summary by CodeRabbit
Bug Fixes
Tests