Skip to content

Raise UnsupportedIncludeError for serializers without relationships - #257

Open
komal0000 wants to merge 3 commits into
jsonapi-serializer:masterfrom
komal0000:fix/include-without-relationships
Open

komal0000 wants to merge 3 commits into
jsonapi-serializer:masterfrom
komal0000:fix/include-without-relationships

Conversation

@komal0000

Copy link
Copy Markdown

Fixes #210, based on the fix @oliver-hohn proposed in #236 (credited as co-author).

Bug: passing include: to a serializer that declares no relationships raised NoMethodError: undefined method '[]' for nil, because relationships_to_serialize stays nil until a relationship is defined. validate_includes! now treats nil as no relationships, so the documented UnsupportedIncludeError is raised. A spec covers it using UserSerializer, which has no relationships.

CI: master no longer passes, for two reasons unrelated to this fix, so I've included two small commits to get CI green again:

  • RuboCop is unpinned with NewCops: enable, and RuboCop 1.92 reports Style/EmptyClassDefinition and Style/DirectiveScope in serialization_core.rb. Fixed without changing behaviour. Pinning RuboCop would stop this recurring, but I've left that to you.
  • ubuntu-latest is now Ubuntu 26.04, where ruby/setup-ruby has no Ruby 2.7, 3.0 or 3.1 builds. The job now runs on ubuntu-24.04, so the matrix stays the same.

Results on my fork: Ruby 2.7, 3.0, 3.1, 3.2, 3.3, 3.4 and head pass (24 examples, 0 failures, no RuboCop offenses): https://github.com/komal0000/jsonapi-serializer/actions/runs/40108791816
Without the fix, the new spec fails with the exact NoMethodError from #210.

truffleruby-head still fails: RuboCop itself errors while inspecting serialization_core.rb on the TruffleRuby nightly. It does this on the unchanged code too, so it isn't caused by this PR.

Happy to help with the other open PRs and issues as well (see #254).

komal0000 and others added 3 commits October 24, 2026 21:27
Passing include: to a serializer that declares no relationships raised
NoMethodError, because relationships_to_serialize is nil until the first
relationship is defined. validate_includes! now treats nil as no
relationships, so the documented UnsupportedIncludeError is raised.

Fixes jsonapi-serializer#210. Based on the fix proposed in jsonapi-serializer#236.

Co-authored-by: Oliver Hohn <17027801+oliver-hohn@users.noreply.github.com>
NewCops is enabled and RuboCop is unpinned, so CI started failing on
master with Style/EmptyClassDefinition and Style/DirectiveScope before
any tests ran.
ubuntu-latest moved to ubuntu-26.04, where ruby/setup-ruby has no builds
for Ruby 2.7, 3.0 or 3.1, so those jobs failed before running.
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.

A serializer without relationships breaks when passing include option to .new

1 participant