ranked-model: undefined method `rank' for nil:NilClass

Sometimes in production (on heroku, rails 5.0.3) I get this error:

undefined method `rank' for nil:NilClass

Here is the stack trace:

/app/vendor/bundle/ruby/2.3.0/gems/ranked-model-0.4.0/lib/ranked-model/ranker.rb:177:in `rearrange_ranks'
/app/vendor/bundle/ruby/2.3.0/gems/ranked-model-0.4.0/lib/ranked-model/ranker.rb:166:in `assure_unique_position'
/app/vendor/bundle/ruby/2.3.0/gems/ranked-model-0.4.0/lib/ranked-model/ranker.rb:61:in `handle_ranking'
/app/vendor/bundle/ruby/2.3.0/gems/ranked-model-0.4.0/lib/ranked-model.rb:31:in `block in handle_ranking'
/app/vendor/bundle/ruby/2.3.0/gems/ranked-model-0.4.0/lib/ranked-model.rb:30:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/ranked-model-0.4.0/lib/ranked-model.rb:30:in `handle_ranking'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.3/lib/active_support/callbacks.rb:382:in `block in make_lambda'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.3/lib/active_support/callbacks.rb:169:in `block (2 levels) in halting'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.3/lib/active_support/callbacks.rb:770:in `block (2 levels) in deprecated_false_terminator'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.3/lib/active_support/callbacks.rb:769:in `catch'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.3/lib/active_support/callbacks.rb:769:in `block in deprecated_false_terminator'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.3/lib/active_support/callbacks.rb:170:in `block in halting'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.3/lib/active_support/callbacks.rb:454:in `block in call'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.3/lib/active_support/callbacks.rb:454:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.3/lib/active_support/callbacks.rb:454:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.3/lib/active_support/callbacks.rb:101:in `__run_callbacks__'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.3/lib/active_support/callbacks.rb:750:in `_run_save_callbacks'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.3/lib/active_record/callbacks.rb:298:in `create_or_update'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.3/lib/active_record/persistence.rb:160:in `save!'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.3/lib/active_record/validations.rb:50:in `save!'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.3/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.3/lib/active_record/transactions.rb:324:in `block in save!'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.3/lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.3/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.3/lib/active_record/transactions.rb:211:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.3/lib/active_record/transactions.rb:392:in `with_transaction_returning_status'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.3/lib/active_record/transactions.rb:324:in `save!'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.3/lib/active_record/suppressor.rb:45:in `save!'

What can I do ? It might be a concurency issue, because it only happen when loading a lot of items concurently.

Thanks in advance for your help.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 5
  • Comments: 16 (7 by maintainers)

Most upvoted comments

@bf4, I think this may now be solved. Try master. Thanks again @fschwahn 😃

At the end of the day I’m maintaining this library on a voluntary basis and don’t have the time to narrow this one down further, but I’m always happy to assist you where I can.

Totally feel that. Fellow (burned out) maintainer here