Skip to content

fix ArgumentError building routes on Rails 8.1 - #1496

Open
SAY-5 wants to merge 1 commit into
JSONAPI-Resources:masterfrom
SAY-5:fix-rails-8-1-resource-argumenterror
Open

SAY-5 wants to merge 1 commit into
JSONAPI-Resources:masterfrom
SAY-5:fix-rails-8-1-resource-argumenterror

Conversation

@SAY-5

@SAY-5 SAY-5 commented Aug 25, 2026

Copy link
Copy Markdown

All Submissions:

  • I've checked to ensure there aren't other open Pull Requests for the same update/change.
  • I've submitted a ticket for my issue if one did not already exist.
  • My submission passes all tests. (Please run the full test suite locally to cut down on noise from travis failures.)
  • I've used Github auto-closing keywords in the commit message or the description.
  • I've added/updated tests for this change.

Bug fixes and Changes to Core Features:

  • I've included an explanation of what the changes do and why I'd like you to include them.
  • I've provided test(s) that fails without the change.

Test Plan:

rake test needs a database and currently errors out on a booted-app requirement in rails/test_help that's unrelated to this change (reproduces the same way on master with Rails 7.2 and 8.1, so it looks like a separate pre-existing gap in test_helper.rb's Rails 8 support). To verify this fix directly I installed actionpack 7.2.2.2 and 8.1.3.1 side by side and drew routes with jsonapi_resources through a real ActionDispatch::Routing::RouteSet#draw, which is what test/unit/routing_ext_test.rb does. That test errors with the exact ArgumentError: wrong number of arguments (given 4, expected 3) from the issue when run against master, and passes on both Rails versions with this change.

Reviewer Checklist:

  • Maintains compliance with JSON:API
  • Adequate test coverage exists to prevent regressions

Fixes #1488

Rails 8.1 changed ActionDispatch::Routing::Mapper::Resource#initialize (and SingletonResource) to take only:/except: as keywords instead of a trailing positional options hash (rails/rails#53689). jsonapi_resource(s) still calls both with a plain positional hash, so drawing any route on Rails 8.1 raises ArgumentError: wrong number of arguments (given 4, expected 3) before the app boots. Passing options with ** instead of positionally works on both the old and the new signature.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@kurko

kurko commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

LGTM, but can you look at the failing test?

@SAY-5

SAY-5 commented Oct 18, 2026

Copy link
Copy Markdown
Author

I checked the failed Ruby 2.7 / Rails 6.0.6 / PostgreSQL job. It ran 675 tests with 8,767 assertions and one failure: RequestTest#test_pagination_related_resources_data_includes, at the cache-warmup equality assertion in test_helper.rb:507 (seed 13850). The diff contains the same ten book_comments IDs in a different order inside the included book's relationship data.

Both that test and its helper are byte-identical between the PR head 96eef89 and base ca2eb53; the PR changes only the two routing constructor calls and their routing tests. The other 27 jobs passed. The base branch's corresponding job also passed, so these results do not establish that the failure is pre-existing or unrelated to this change.

I have not reproduced the failure with the matching Ruby/Rails/PostgreSQL setup, so the cause remains unverified. The next diagnostic is a base-versus-head run with seed 13850, tracing the relationship query ordering with and without caching. No assertion or test has been weakened, and no CI repair is claimed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArgumentError with Rails 8.1

2 participants