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

crash: undefined method `[]=' for nil:NilClass (NoMethodError) #166

Closed
tmornini opened this issue Aug 4, 2015 · 11 comments · Fixed by #168
Closed

crash: undefined method `[]=' for nil:NilClass (NoMethodError) #166

tmornini opened this issue Aug 4, 2015 · 11 comments · Fixed by #168
Labels

Comments

@tmornini
Copy link

tmornini commented Aug 4, 2015

Hey guys. Updating to 0.4.6 or 0.4.7 crashes on the following code which has run unchanged since the 0.3.0 days. :-)

Grape::Entity.format_with :id do |entity|
                                entity.id unless entity.nil?
                              end
/Users/tmornini/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/grape-entity-0.4.7/lib/grape_entity/entity.rb:243:in `format_with': undefined method `[]=' for nil:NilClass (NoMethodError)
    from /Users/tmornini/subledger/subledger/lib/subledger/domain/formatters.rb:1:in `<top (required)>'
    from /Users/tmornini/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
    from /Users/tmornini/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
    from /Users/tmornini/subledger/subledger/lib/subledger/domain.rb:94:in `<top (required)>'
    from /Users/tmornini/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/tmornini/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/tmornini/subledger/subledger/lib/subledger.rb:17:in `<top (required)>'
    from /Users/tmornini/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/tmornini/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/tmornini/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/irb/init.rb:281:in `block in load_modules'
    from /Users/tmornini/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/irb/init.rb:279:in `each'
    from /Users/tmornini/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/irb/init.rb:279:in `load_modules'
    from /Users/tmornini/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/irb/init.rb:20:in `setup'
    from /Users/tmornini/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/irb.rb:53:in `start'
    from /Users/tmornini/.rbenv/versions/1.9.3-p551/bin/irb:12:in `<main>'
@marshall-lee
Copy link
Member

@tmornini please provide an example how you use :format_with option.

@marshall-lee
Copy link
Member

ah, sorry.

@marshall-lee
Copy link
Member

@dblock

I bet it's caused by #134.

Defining global formatters on Grape::Entity is not documented and has no specs. However, I don't see anything harmful in this. What do you think?

@marshall-lee
Copy link
Member

@tmornini

As a quick fix I can propose you not to define global formatters on Grape::Entity but make a base class for all of your entity classes and setup formatter in it.

As I said such possibility is not documented so if you think that it should exist lets discuss it.

@marshall-lee
Copy link
Member

There's also an issue #161. It's about exposures but it propagates to formatters and other things too. It can bite someone who defines global formatters on Grape::Entity after creating a subclass from Grape::Entity — they simple won't get that formatter in a subclass.

@dblock
Copy link
Member

dblock commented Aug 4, 2015

@marshall-lee sounds like you have it all covered, do what you have to do

@tmornini
Copy link
Author

@marshall-lee Like this?

class EntityBase < Grape::Entity
  format_with :id do |entity|
                    entity.id unless entity.nil?
                  end
end

@marshall-lee
Copy link
Member

@tmornini yes.

Also i will fix it soon, so maybe you don't have to change your existing code if you just wait a bit :)

@tmornini
Copy link
Author

@marshall-lee Even better! :-)

marshall-lee added a commit to marshall-lee/grape-entity that referenced this issue Aug 10, 2015
This fixes a regression introduced after merging a ruby-grape#134.
It's something undocumented before but it worked before and I don't see
anything harmful in the presence of this feature.

Fixes ruby-grape#166.
marshall-lee added a commit to marshall-lee/grape-entity that referenced this issue Aug 10, 2015
This fixes a regression introduced after merging a ruby-grape#134.
It's something undocumented before but it worked before and I don't see
anything harmful in the presence of this feature.

Fixes ruby-grape#166.
marshall-lee added a commit to marshall-lee/grape-entity that referenced this issue Aug 10, 2015
This fixes a regression introduced after merging a ruby-grape#134.
It's something undocumented before but it worked before and I don't see
anything harmful in the presence of this feature.

Fixes ruby-grape#166.
marshall-lee added a commit to marshall-lee/grape-entity that referenced this issue Aug 10, 2015
This fixes a regression introduced after merging a ruby-grape#134.
It's something undocumented before but it worked before and I don't see
anything harmful in the presence of this feature.

Fixes ruby-grape#166.
marshall-lee added a commit to marshall-lee/grape-entity that referenced this issue Aug 10, 2015
This fixes a regression introduced after merging a ruby-grape#134.
It's something undocumented before but it worked before and I don't see
anything harmful in the presence of this feature.

Fixes ruby-grape#166.
marshall-lee added a commit to marshall-lee/grape-entity that referenced this issue Aug 10, 2015
This fixes a regression introduced after merging a ruby-grape#134.
It's something undocumented before but it worked before and I don't see
anything harmful in the presence of this feature.

Fixes ruby-grape#166.

Conflicts:
	.rubocop_todo.yml
	CHANGELOG.md
	lib/grape_entity/entity.rb
	lib/grape_entity/version.rb
	spec/grape_entity/entity_spec.rb
marshall-lee added a commit to marshall-lee/grape-entity that referenced this issue Aug 10, 2015
This fixes a regression introduced after merging a ruby-grape#134.
It's something undocumented before but it worked before and I don't see
anything harmful in the presence of this feature.

Fixes ruby-grape#166.

Conflicts:
	.rubocop_todo.yml
	CHANGELOG.md
	lib/grape_entity/entity.rb
	lib/grape_entity/version.rb
	spec/grape_entity/entity_spec.rb
marshall-lee added a commit to marshall-lee/grape-entity that referenced this issue Aug 10, 2015
This fixes a regression introduced after merging a ruby-grape#134.
It's something undocumented before but it worked before and I don't see
anything harmful in the presence of this feature.

Fixes ruby-grape#166.
@marshall-lee
Copy link
Member

@tmornini please try out 0.4.8

@tmornini
Copy link
Author

@marshall-lee 0.4.8 has resolved our issue.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants