Repository navigation
fix: avoid config hash crash for non-serializable values - #4241
Conversation
📝 WalkthroughWalkthrough
ChangesConfiguration hash fallback
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/snakemake/workflow.py`:
- Around line 283-288: In the info_header configuration hash logic, replace the
undefined config reference in the json.dumps call with self.config, while
preserving the existing MD5 calculation and TypeError fallback to "unavailable".
🪄 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: f8d5e3ac-e6ea-4511-82d3-ef007e1d343f
📒 Files selected for processing (2)
src/snakemake/workflow.pytests/tests.py
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/snakemake/workflow.py (1)
283-288: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low valueConsider also catching
ValueErrorfor circular references.
json.dumpsraisesValueError(notTypeError) when it encounters circular references in the config. If that occurs, the workflow would still fail to start — the same failure mode this PR aims to prevent. Catchingexcept (TypeError, ValueError)would broaden the graceful fallback to cover that edge case with no additional cost.This is optional and beyond the stated scope of issue
#4215, which specifically mentionsTypeError.♻️ Optional refactor
try: config_md5 = hashlib.md5( json.dumps(self.config, sort_keys=True).encode("utf-8") ).hexdigest() - except TypeError: + except (TypeError, ValueError): config_md5 = "unavailable"🤖 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 `@src/snakemake/workflow.py` around lines 283 - 288, In the config hash computation within the workflow initialization logic, broaden the existing TypeError handler around json.dumps to also catch ValueError, so circular config references use the "unavailable" fallback instead of aborting startup.
🤖 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.
Nitpick comments:
In `@src/snakemake/workflow.py`:
- Around line 283-288: In the config hash computation within the workflow
initialization logic, broaden the existing TypeError handler around json.dumps
to also catch ValueError, so circular config references use the "unavailable"
fallback instead of aborting startup.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5ab6d4f0-f05c-4fe9-bb69-027b376bc261
📒 Files selected for processing (1)
src/snakemake/workflow.py
|
Thanks for the suggestion. I verified that circular references raise The fallback remains limited to config hash generation, and JSON-serializable configs keep the existing deterministic MD5 behavior. |
johanneskoester
left a comment
There was a problem hiding this comment.
Thanks a lot, good catch!
) Fixes snakemake#4215. Workflow startup logging calculates `config_md5` with `json.dumps(..., sort_keys=True)`. This can fail before workflow execution when runtime config contains values that JSON cannot serialize, such as `pathlib.Path`, or values that produce JSON serialization value errors, such as circular references. This change preserves the existing deterministic MD5 calculation for JSON-serializable configs. If serialization raises `TypeError` or `ValueError`, the startup header reports `Config MD5: unavailable` instead of crashing. The config object is not mutated, and arbitrary values are not stringified with `default=str`. Validation: - `env XDG_CACHE_HOME="$PWD/.cache" PYTHONPATH=src .venv/bin/python3.12 -m pytest tests/tests.py::test_config tests/tests.py::test_config_non_json_serializable -q` - `env XDG_CACHE_HOME="$PWD/.cache" PYTHONPATH=src .venv/bin/python3.12 -m pytest tests/tests.py -k "config" -q` - `.venv/bin/black --check src/snakemake/workflow.py tests/tests.py` - `git diff --check` - manual reproduction with `pathlib.Path` config - manual reproduction with circular config - deterministic MD5 verification for ordinary JSON config ### QC <!-- Make sure that you can tick the boxes below. --> * [x] The PR contains a test case for the changes or the changes are already covered by an existing test case. * [x] 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). * [x] I, as a human being, have checked each line of code in this pull request ### AI-assistance disclosure <!-- If AI tools were involved in creating this PR, please check all boxes that apply below and make sure that you adhere to our AI-assisted contributions policy: https://github.com/snakemake/snakemake/blob/main/docs/project_info/contributing.rst --> I used AI assistance for: * [x] Code generation (e.g., when writing an implementation or fixing a bug) * [x] Test/benchmark generation * [ ] Documentation (including examples) * [x] Research and understanding <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Workflow information no longer fails when configuration contains non–JSON-serializable values. * Shows an “unavailable” configuration checksum instead of erroring. * **Tests** * Added a new test to cover workflows using non–JSON-serializable configuration inputs. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
🤖 I have created a release *beep* *boop* --- ## [9.24.0](v9.23.1...v9.24.0) (2026-07-30) ### Features * allow to combine cases with otherwise in branch function ([#4262](#4262)) ([000ff52](000ff52)) ### Bug Fixes * avoid config hash crash for non-serializable values ([#4241](#4241)) ([1a27746](1a27746)) * compilation error when final line contains an f-string ([#4234](#4234)) ([9c5e7fe](9c5e7fe)) * Group error log formatting ([#4256](#4256)) ([bb6dcde](bb6dcde)) * leak of benchmark monitor threads ([#4259](#4259)) ([d37852e](d37852e)) * no benchmark warning when a process exits before it can be sampled ([#4260](#4260)) ([6738359](6738359)) * persistence starttime unset/defaults ([#4251](#4251)) ([56395c0](56395c0)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Fixes #4215.
Workflow startup logging calculates
config_md5withjson.dumps(..., sort_keys=True). This can fail before workflow execution when runtime config contains values that JSON cannot serialize, such aspathlib.Path, or values that produce JSON serialization value errors, such as circular references.This change preserves the existing deterministic MD5 calculation for JSON-serializable configs. If serialization raises
TypeErrororValueError, the startup header reportsConfig MD5: unavailableinstead of crashing. The config object is not mutated, and arbitrary values are not stringified withdefault=str.Validation:
env XDG_CACHE_HOME="$PWD/.cache" PYTHONPATH=src .venv/bin/python3.12 -m pytest tests/tests.py::test_config tests/tests.py::test_config_non_json_serializable -qenv XDG_CACHE_HOME="$PWD/.cache" PYTHONPATH=src .venv/bin/python3.12 -m pytest tests/tests.py -k "config" -q.venv/bin/black --check src/snakemake/workflow.py tests/tests.pygit diff --checkpathlib.PathconfigQC
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).AI-assistance disclosure
I used AI assistance for:
Summary by CodeRabbit