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

ArgumentError: wrong number of arguments (given 0, expected 1+) #2173

Closed
bsa7 opened this issue Aug 7, 2017 · 4 comments
Closed

ArgumentError: wrong number of arguments (given 0, expected 1+) #2173

bsa7 opened this issue Aug 7, 2017 · 4 comments

Comments

@bsa7
Copy link

bsa7 commented Aug 7, 2017

Expected behavior vs actual behavior

in lib/active_model/serializer.rb:340:in initialize'`:

return Enumerator.new unless object

throw error:
ArgumentError: wrong number of arguments (given 0, expected 1+)

Steps to reproduce

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

when i read documentation for Enumerator, i'm find, that it's expect minimum one argument, but in line 340 no arguments passed.

Environment

ActiveModelSerializers Version 0.10.6:

Output of ruby -e "puts RUBY_DESCRIPTION": ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

OS Type & Version: Linux u116 4.10.0-19-generic #21-Ubuntu SMP Thu Apr 6 17:04:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Integrated application and version (e.g., Rails, Grape, etc):
rails-5.0.5

Backtrace

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

../active_model_serializers-0.10.6/lib/active_model/serializer.rb:340:in `initialize'",
../active_model_serializers-0.10.6/lib/active_model/serializer.rb:340:in `new'",
../active_model_serializers-0.10.6/lib/active_model/serializer.rb:340:in `associations'",
../active_model_serializers-0.10.6/lib/active_model/serializer/concerns/caching.rb:195:in `block in object_cache_keys'",
../active_model_serializers-0.10.6/lib/active_model/serializer/collection_serializer.rb:5:in `each'",
../active_model_serializers-0.10.6/lib/active_model/serializer/collection_serializer.rb:5:in `each'",
../active_model_serializers-0.10.6/lib/active_model/serializer/concerns/caching.rb:192:in `object_cache_keys'",
../active_model_serializers-0.10.6/lib/active_model/serializer/concerns/caching.rb:177:in `cache_read_multi'",
../active_model_serializers-0.10.6/lib/active_model/serializer/collection_serializer.rb:23:in `serializable_hash'",
../active_model_serializers-0.10.6/lib/active_model/serializer/association.rb:56:in `serializable_hash'",
../active_model_serializers-0.10.6/lib/active_model/serializer.rb:401:in `block in associations_hash'",
../active_model_serializers-0.10.6/lib/active_model/serializer.rb:348:in `yield'",
../active_model_serializers-0.10.6/lib/active_model/serializer.rb:348:in `block (2 levels) in associations'",
../active_model_serializers-0.10.6/lib/active_model/serializer.rb:343:in `each'",
../active_model_serializers-0.10.6/lib/active_model/serializer.rb:343:in `block in associations'",
../active_model_serializers-0.10.6/lib/active_model/serializer.rb:399:in `each'",
../active_model_serializers-0.10.6/lib/active_model/serializer.rb:399:in `each_with_object'",
../active_model_serializers-0.10.6/lib/active_model/serializer.rb:399:in `associations_hash'",
../active_model_serializers-0.10.6/lib/active_model/serializer.rb:360:in `serializable_hash'",

Additonal helpful information

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

AMS 0.10.6

@andrjuha01
Copy link

@r72cccp Sorry, I can be wrong right here, but in documentation you can really find another example of creating object.
new(size = nil) { |yielder| ... }.
In that way, the size would be nil, but it would yield a block given after it.
Like here:

fib = Enumerator.new do |y|
  a = b = 1
  loop do
    y << a
    a, b = b, a + b
  end
end

@drn
Copy link

drn commented Aug 29, 2017

I ran into this as well.

I didn't track down the reason why object did not exist, but this pull addresses the issue -
#2179

irb(main):001:0> Enumerator.new
ArgumentError: wrong number of arguments (given 0, expected 1+)
        from (irb):1:in `initialize'
        from (irb):1:in `new'
        from (irb):1
        from /Users/darrencheng/.rbenv/versions/2.3.0/bin/irb:11:in `<main>'
irb(main):002:0> Enumerator.new { }
=> #<Enumerator: #<Enumerator::Generator:0x007fdc64b55a20>:each>

@bf4
Copy link
Member

bf4 commented Aug 29, 2017

Hmm, don't know how I missed that in implementation and test

@bf4
Copy link
Member

bf4 commented Oct 30, 2017

Fixed by #2179

@bf4 bf4 closed this as completed Oct 30, 2017
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

4 participants