Skip to content

fix: ensure that strings that purely contain integers or floats (e.g. "42") remain strings when parsing profiles#4119

Merged
johanneskoester merged 6 commits intomainfrom
johanneskoester-patch-1
Mar 24, 2026
Merged

fix: ensure that strings that purely contain integers or floats (e.g. "42") remain strings when parsing profiles#4119
johanneskoester merged 6 commits intomainfrom
johanneskoester-patch-1

Conversation

@johanneskoester
Copy link
Copy Markdown
Contributor

@johanneskoester johanneskoester commented Mar 19, 2026

fixes #3992

QC

  • The PR contains a test case for the changes or the changes are already covered by an existing test case.
  • The documentation (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).
  • I, as a human being, have checked each line of code in this pull request

AI-assistance disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Summary by CodeRabbit

  • Bug Fixes
    • CLI-style configuration output now preserves integer/float-like string values by quoting them so they aren’t misinterpreted; non-string values retain prior formatting.
  • Chores
    • Profile parsing now emits brief debug output during execution.
  • Tests
    • Added unit tests covering profile parsing and CLI-style serialization to ensure values are preserved and evaluate correctly.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 19, 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

Added a helper that converts numeric-like strings to repr(...) when serializing profile values, applied it to one- and two-level CLI-style formatting, and added an unconditional debug print of the serialized result and parsed YAML. Also added a unit test verifying parsing and evaluation of a numeric-like profile value.

Changes

Cohort / File(s) Summary
Profile Value Serialization & Debugging
src/snakemake/profiles.py
Added format_val(val) to detect/format integer/float-like strings with repr(...) and applied it in one- and two-level serialization paths; added an unconditional print(result, parsed_obj) at the end of ProfileConfigFileParser.parse().
Tests
tests/test_internals.py
Added test_profile_parse creating an in-memory YAML profile, parsing it via ProfileConfigFileParser().parse(stream), asserting the serialized entry ["rule1:slurm_partition='42'"], and verifying the evaluated slurm_partition yields the string "42".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

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 ⚠️ Warning The PR description is incomplete. The test case checkbox is unchecked despite tests being added in the raw summary, and no explanation of the fix is provided. Check the test case checkbox since test_profile_parse was added, and provide a brief explanation of the changes made to fix issue #3992.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: preserving numeric-like strings as strings during profile parsing, which matches the code modifications in profiles.py that add format_val() to handle this scenario.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch johanneskoester-patch-1

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
Contributor

@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

🤖 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/snakemake/profiles.py`:
- Around line 28-35: The serializer is quoting strings with repr() in
format_val, which changes semantics; change format_val to return string values
unchanged (do not call repr) and ensure format_one_level_dict (and any other
places that call format_val) emit raw string content (e.g., key=val) so
numeric-like strings are preserved without added quotes; update format_val to
only format non-string types as needed and remove repr usage in both format_val
and the similar call at the other occurrence referenced (line 43).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 632f6cc0-23ca-48da-b916-6725aa0b0d76

📥 Commits

Reviewing files that changed from the base of the PR and between 4bba4a9 and 1935a06.

📒 Files selected for processing (1)
  • src/snakemake/profiles.py

Comment on lines +28 to +35
def format_val(val):
if isinstance(val, str):
return repr(val)
else:
return val

def format_one_level_dict(d):
return [f"{key}={val}" for key, val in d.items()]
return [f"{key}={format_val(val)}" for key, val in d.items()]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

repr() here changes value semantics and breaks profile parsing.

At Line 30, repr(val) adds literal quotes to string values. At Line 35 and Line 43 this emits entries like a='grp1' / rule:key='val' instead of a=grp1 / rule:key=val, which alters parsed values and can break existing behavior (notably groups/group-components style mappings).

Please avoid repr-based quoting in this serializer path; keep raw string content and handle numeric-string preservation where type coercion actually happens.

Suggested minimal correction
-        def format_val(val):
-            if isinstance(val, str):
-                return repr(val)
-            else:
-                return val
+        def format_val(val):
+            return val

Also applies to: 43-43

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

In `@src/snakemake/profiles.py` around lines 28 - 35, The serializer is quoting
strings with repr() in format_val, which changes semantics; change format_val to
return string values unchanged (do not call repr) and ensure
format_one_level_dict (and any other places that call format_val) emit raw
string content (e.g., key=val) so numeric-like strings are preserved without
added quotes; update format_val to only format non-string types as needed and
remove repr usage in both format_val and the similar call at the other
occurrence referenced (line 43).

Copy link
Copy Markdown
Contributor

@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/snakemake/profiles.py`:
- Line 87: Remove the stray debug print call print(result, parsed_obj) so it
does not emit to stdout on every CLI invocation; if you need the information for
debugging retain it via a logger (e.g., logger.debug("profile parse result=%s
parsed_obj=%s", result, parsed_obj)) in the same function that produces result
and parsed_obj so normal runs remain silent and downstream parsers aren’t
broken.
- Line 9: Replace the plain-string int_re with a raw regex that matches integers
or floats (e.g. change int_re = re.compile("^-?\d+$") to a raw pattern such as
numeric_re = re.compile(r"^-?\d+(\.\d+)?$") and then update the reference in
format_val to use numeric_re; this ensures \d is handled correctly and values
like "3.14" and "-0.5" are recognized as numeric by the existing logic that
preserves numbers-as-strings.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 47bb670b-ea9f-460d-b077-c0a8df2fcb7f

📥 Commits

Reviewing files that changed from the base of the PR and between 860c10c and b282caf.

📒 Files selected for processing (1)
  • src/snakemake/profiles.py


result[key] = value

print(result, parsed_obj)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Remove debug print statement before merging.

This print(result, parsed_obj) will execute on every CLI invocation that loads a profile, producing unintended output to stdout during normal operation. This can break downstream tooling that parses Snakemake output and degrades user experience.

Proposed fix
-        print(result, parsed_obj)
         return result
📝 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(result, parsed_obj)
return result
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/snakemake/profiles.py` at line 87, Remove the stray debug print call
print(result, parsed_obj) so it does not emit to stdout on every CLI invocation;
if you need the information for debugging retain it via a logger (e.g.,
logger.debug("profile parse result=%s parsed_obj=%s", result, parsed_obj)) in
the same function that produces result and parsed_obj so normal runs remain
silent and downstream parsers aren’t broken.

@andynu
Copy link
Copy Markdown

andynu commented Mar 19, 2026

Scenario sbatch -p Result
Serial + Unquoted (20) -p 20 PASS (trivially, 1 job/layer)
Parallel + Unquoted (20) -p 40 FAIL - bug reproduced
Serial + Quoted ("20") -p 20 PASS
Parallel + Quoted ("20") -p 20 PASS - PR fix works

This does appear to fix the issue when we explicitly quote the partition name.

@johanneskoester
Copy link
Copy Markdown
Contributor Author

Thanks for your help @andynu!

@johanneskoester johanneskoester merged commit 3ca08e1 into main Mar 24, 2026
61 checks passed
@johanneskoester johanneskoester deleted the johanneskoester-patch-1 branch March 24, 2026 10:46
johanneskoester pushed a commit that referenced this pull request Mar 24, 2026
🤖 I have created a release *beep* *boop*
---


##
[9.17.3](v9.17.2...v9.17.3)
(2026-03-24)


### Bug Fixes

* add curl when containerize with wrapper
([#4115](#4115))
([44979e4](44979e4))
* ensure proper wrapper prefix is passed to CWL and shown in wrapper
error messages
([#4121](#4121))
([11b6f29](11b6f29))
* ensure that strings that purely contain integers or floats (e.g. "42")
remain strings when parsing profiles
([#4119](#4119))
([3ca08e1](3ca08e1))
* incorrect highlighting in HTML report
([#4120](#4120))
([1ef224d](1ef224d))


### Documentation

* document an accidental (sorry) recent breaking change in type checking
compatibility of Python scripts, in favor of a clean and robust new
syntax ([#4116](#4116))
([013bc43](013bc43))
* Rework tutorial
([#4068](#4068))
([4bba4a9](4bba4a9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
  * Released version 9.17.3

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

Numeric Slurm Partition Names Summed in Snakemake Group Jobs

2 participants