Skip to content

Don't modify the caller's options hash in results - #77

Merged
Sija merged 1 commit into
masterfrom
fix/results-options-mutation
Nov 21, 2026
Merged

Sija merged 1 commit into
masterfrom
fix/results-options-mutation

Conversation

@Sija

@Sija Sija commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

 def results(profile, options = {})
-  return all_results(profile, options) if options.delete(:all)
+  if options[:all]
+    return all_results(profile, options.reject { |key, _| key == :all })
+  end

options.delete(:all) removed :all from the caller's own hash, so reusing that hash for a second call silently fetched a single page.

Evidence

  • Before:
    options = { all: true, offset: 1 }
    results(profile, options)
    options  # => Expected: {:all=>true, :offset=>1}
             #      Actual: {:offset=>1}
    127 tests, 224 assertions, 1 failures, 0 errors
    
    After: 127 tests, 224 assertions, 0 failures, 0 errors

Merge Danger

Door: two-way

Blast Radius: minimal

Only callers relying on :all being removed from their hash would notice.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fetching all results no longer removes the all option from the options provided by the caller. The original options remain available for reuse, while a truthy all value still requests all results and false or nil continues to use the regular results path.

`options.delete(:all)` removed `:all` from the hash passed in by the caller, so reusing the same options hash for a second call silently fetched only a single page. Pass a copy without `:all` to `all_results` instead.

Assisted-by: Claude:claude-opus-5-5
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

Model.results now preserves the caller’s options hash when :all is set. A test verifies that the hash remains unchanged after the call.

Changes: Results options

Layer / File(s) Summary
Preserve options during results lookup
lib/garb/model.rb, test/unit/garb/model_test.rb
results checks options[:all] without deleting it from the caller’s hash and passes a copy without :all to all_results. The test verifies that the original hash remains unchanged.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: dblock

Merge Risk: Moderate · up to 439f9

The change stops results from altering the caller's options hash, but callers that pass an indifferent-access hash (for example Rails-style params) with all: true would hit infinite recursion and a stack overflow. Switching to a duplicated hash with delete(:all) fixes this before merge.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@Sija
Sija merged commit 43a251a into master Nov 21, 2026
6 of 7 checks passed
@Sija Sija added the bug label Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant