Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise ArgumentError "Cannot infer root key from collection type. Please specify the root or each_serializer option, or render a JSON String" when collection is empty array in >= 10.0.7 #2406

Closed
tashirosota opened this issue Jan 23, 2021 · 0 comments

Comments

@tashirosota
Copy link

tashirosota commented Jan 23, 2021

Expected behavior vs actual behavior

  • 【Expected behavior】※ <= version 10.0.6
::ActiveModelSerializers::SerializableResource.new(
  collections, # [] empty array
  each_serializer: CollectionSerializer,
).serializable_hash
=> { collection_types: nil }

  • 【Actual behavior】※ >= version 10.0.7
::ActiveModelSerializers::SerializableResource.new(
  collections, # [] empty array
  each_serializer: CollectionSerializer,
).serializable_hash
=> Raise ArgumentError  "Cannot infer root key from collection type. Please specify the root or each_serializer option, or render a JSON String"

Is this breaking change or bug?

Steps to reproduce

(e.g., detailed walkthrough, runnable script, example application)

# >= version 10.0.7
::ActiveModelSerializers::SerializableResource.new(
  collections, # [] empty array
  each_serializer: CollectionSerializer,
).serializable_hash

Environment

ActiveModelSerializers Version (commit ref if not on tag): >= 10.0.7

Output of ruby -e "puts RUBY_DESCRIPTION": ruby 2.6.6p146 && 2.5.1

OS Type & Version: alpine3.12 on docker

Integrated application and version (e.g., Rails, Grape, etc): Rails 5.2.4.4 & 5.1.6

Backtrace

(e.g., provide any applicable backtraces from your application)

Additonal helpful information

(e.g., Gemfile.lock, configurations, PR containing a failing test, git bisect results)

In PR #2214, @mvz said「I'm getting this error on a line that does have :each_serializer specified 😞」. Me too.

@tashirosota tashirosota changed the title Raise ArgumentError "Cannot infer root key from collection type. Please specify the root or each_serializer option, or render a JSON String" when collection is empty array in over version 10.0.7 Raise ArgumentError "Cannot infer root key from collection type. Please specify the root or each_serializer option, or render a JSON String" when collection is empty array in >= 10.0.7 Jan 23, 2021
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

No branches or pull requests

1 participant