Skip to content

Make the cascade DSL getter return the configured value#2827

Open
ericproulx wants to merge 1 commit into
masterfrom
fix-cascade-dsl-getter
Open

Make the cascade DSL getter return the configured value#2827
ericproulx wants to merge 1 commit into
masterfrom
fix-cascade-dsl-getter

Conversation

@ericproulx

Copy link
Copy Markdown
Contributor

Problem

The cascade DSL getter doesn't return what was configured:

def cascade(value = nil)
  return inheritable_setting.cascade_defined? ? !inheritable_setting.cascade.nil? : true if value.nil?

  inheritable_setting.cascade = value
end

!cascade.nil? answers "was cascade set to a non-nil value", not "does this API cascade". So:

class API < Grape::API
  cascade false
end

API.cascade  # => true (!)

…while the runtime honors the setting correctly — Grape::API::Instance#cascade? returns false and the X-Cascade header is stripped. The getter simply contradicts the actual behavior it's supposed to report. The !value.nil? shape goes back at least to v2.4.0 (!namespace_inheritable(:cascade).nil?), so this is long-standing, not a recent regression.

Fix

Return the stored value when one was configured, true (the documented default) otherwise:

return inheritable_setting.cascade_defined? ? inheritable_setting.cascade : true if value.nil?

The getter now always agrees with Instance#cascade? for every configured value, including the degenerate cascade nil case (both report falsy — previously the getter said false while meaning "set to nil").

Compatibility

Strictly speaking this changes a public getter's return value: anyone using API.cascade to detect "was cascade called at all" (rather than its meaning) would see false instead of true after cascade false. Since the next release is 4.0.0, this lands with an UPGRADING note; the existing .cascade spec is extended to cover unset / true / false.

🤖 Generated with Claude Code

`cascade` with no argument returned `!cascade.nil?` — i.e. whether
cascading had been configured at all — so `cascade false` read back as
true, contradicting the runtime behavior (Instance#cascade? correctly
returns false). Return the stored value itself, or true when never set.

Present since at least v2.4.0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ericproulx
ericproulx force-pushed the fix-cascade-dsl-getter branch from f23d314 to 7b3fa7d Compare July 26, 2026 19:37
@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

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.

2 participants