Skip to content

feat: allow to combine cases with otherwise in branch function - #4262

Merged
johanneskoester merged 2 commits into
mainfrom
feat/branch-cases-otherwise
Jul 30, 2026
Merged

johanneskoester merged 2 commits into
mainfrom
feat/branch-cases-otherwise

Conversation

@johanneskoester

@johanneskoester johanneskoester commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

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

  • New Features

    • Added support for using an otherwise fallback when a branch() condition does not match any key in cases.
  • Bug Fixes

    • Improved error handling for unmatched branch conditions, including clearer KeyError messages.
    • Updated validation to allow cases and otherwise to be used together.
  • Documentation

    • Added guidance and examples for configuring fallback behavior with otherwise.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

branch() now supports otherwise when a selected cases key is missing, while retaining KeyError behavior without a fallback. Documentation describes both outcomes and provides a fallback example.

Changes

Branch case fallback

Layer / File(s) Summary
Case fallback behavior
src/snakemake/ioutils/branch.py, docs/snakefiles/rules.rst
branch() permits otherwise with cases, evaluates it for missing keys, and documents the fallback and KeyError behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: fgvieira

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title matches the main change: allowing branch() cases to combine with otherwise.
Description check ✅ Passed The required QC and AI-assistance sections are present and mostly complete, though no freeform summary is provided.
✨ 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 feat/branch-cases-otherwise

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.

@coderabbitai coderabbitai Bot left a comment

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.

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/ioutils/branch.py`:
- Around line 49-51: Update the missing-case raise in the branch handling logic
after handle_callable(otherwise, wildcards) to use from None, suppressing the
underlying mapping lookup KeyError while preserving the existing custom error
message.
🪄 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 Plus

Run ID: 8a120197-ad3b-4641-9eb5-ffe07d46da47

📥 Commits

Reviewing files that changed from the base of the PR and between bb6dcde and 67705ea.

📒 Files selected for processing (2)
  • docs/snakefiles/rules.rst
  • src/snakemake/ioutils/branch.py

Comment thread src/snakemake/ioutils/branch.py Resolved
@johanneskoester
johanneskoester merged commit 000ff52 into main Jul 30, 2026
87 checks passed
@johanneskoester
johanneskoester deleted the feat/branch-cases-otherwise branch July 30, 2026 10:38
johanneskoester pushed a commit that referenced this pull request Jul 30, 2026
🤖 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).
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