JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

UUIDResource has_many IdResource causes undefined method `[]` when doing GET [...]?includes=

Open
#1,156 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

This issue is a (choose one):

  • Problem/bug report.

Description

I've tracked the issue to lib/jsonapi/processor.rb:587.

resource_set[resource_klass] is holding the associated resources in an array key'd by a string {"1" => [...]} and attempting to access it via an int resource.id.

With the following resources just issue this get request (make sure to have include=).

GET /uuids/3bbaf722-4583-4fa6-ac36-9190d4b93f80?include=ids

class UuidResource < JSONAPI::Resource
  key_type :uuid
  has_many :ids
end

class IdResource < JSONAPI::Resource
  has_one :uuid
end

Throws error:

Internal Server Error: undefined method `[]' for nil:NilClass /var/lib/gems/2.3.0/bundler/gems/jsonapi-resources-d185ebb76cd2/lib/jsonapi/processor.rb:587:in `block (2 levels) in populate_resource_set'
/var/lib/gems/2.3.0/bundler/gems/jsonapi-resources-d185ebb76cd2/lib/jsonapi/processor.rb:586:in `each'
/var/lib/gems/2.3.0/bundler/gems/jsonapi-resources-d185ebb76cd2/lib/jsonapi/processor.rb:586:in `block in populate_resource_set'
/var/lib/gems/2.3.0/bundler/gems/jsonapi-resources-d185ebb76cd2/lib/jsonapi/processor.rb:542:in `each_key'

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at lib/jsonapi/processor.rb:587 and reproduce the failure with GET /uuids/3bbaf722-4583-4fa6-ac36-9190d4b93f80?include=ids using the UuidResource and IdResource definitions in the issue. Trace how resource_set keys are created and accessed, then verify that the request completes without the undefined method [] error and includes the associated ids.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.