Closed nbcraft closed 4 years ago
Hi @nbcraft, thank you for the thorough bug report. We actually fixed this recently bu using your second suggested fix. Can you try with master
and let me know if the issue is fixed for you?
Hi @brendon , thank you for that information, it does fix the issue! We'll be using the latest commit until a new version gets released.
Thanks a lot.
Thanks Nathan, I'll do a new release for you :)
Fixed by https://github.com/mixonic/ranked-model/pull/160 Waiting for new release superior than
v0.4.4
Hello,
I'm experiencing an issue when changing the scope and sending to the first position at the same time for 2 rows inside a transaction, and I'm suspecting it's because I'm around
MIN_RANK_VALUE
.I don't know if I'm doing something wrong of if this is a legitimate bug, here's the information I've gathered so far:
My situation:
Table creation:
t.bigint :row_order, null: false
Model
All rows with scope_1 = 114
What I'm doing:
Inside a transaction:
scope_2 = 18
androw_order_position = :first
scope_2 = 18
androw_order_position = :first
My Code (renamed):
The crash
The first update (for
id: 12459
) seems to go through, but the second one fails here: (And then everything gets rolled back)StackTrace
Click to Reveal StackTrace
``` undefined method `<' for nil:NilClass /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ranked-model-0.4.4/lib/ranked-model/ranker.rb:215:in `rebalance_ranks' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ranked-model-0.4.4/lib/ranked-model/ranker.rb:169:in `rank_at_average' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ranked-model-0.4.4/lib/ranked-model/ranker.rb:125:in `update_index_from_position' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ranked-model-0.4.4/lib/ranked-model/ranker.rb:60:in `handle_ranking' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ranked-model-0.4.4/lib/ranked-model.rb:33:in `block in handle_ranking' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ranked-model-0.4.4/lib/ranked-model.rb:32:in `each' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ranked-model-0.4.4/lib/ranked-model.rb:32:in `handle_ranking' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2/lib/active_support/callbacks.rb:429:in `block in make_lambda' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2/lib/active_support/callbacks.rb:201:in `block (2 levels) in halting' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2/lib/active_support/callbacks.rb:607:in `block (2 levels) in default_terminator' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2/lib/active_support/callbacks.rb:606:in `catch' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2/lib/active_support/callbacks.rb:606:in `block in default_terminator' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2/lib/active_support/callbacks.rb:202:in `block in halting' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2/lib/active_support/callbacks.rb:514:in `block in invoke_before' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2/lib/active_support/callbacks.rb:514:in `each' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2/lib/active_support/callbacks.rb:514:in `invoke_before' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2/lib/active_support/callbacks.rb:134:in `run_callbacks' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2/lib/active_support/callbacks.rb:827:in `_run_save_callbacks' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/callbacks.rb:328:in `create_or_update' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/timestamp.rb:129:in `create_or_update' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/persistence.rb:503:in `save!' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/validations.rb:53:in `save!' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/transactions.rb:319:in `block in save!' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/transactions.rb:375:in `block in with_transaction_returning_status' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:279:in `transaction' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/transactions.rb:212:in `transaction' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/transactions.rb:366:in `with_transaction_returning_status' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/transactions.rb:319:in `save!' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/suppressor.rb:48:in `save!' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/persistence.rb:635:in `block in update!' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/transactions.rb:375:in `block in with_transaction_returning_status' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:279:in `transaction' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/transactions.rb:212:in `transaction' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/transactions.rb:366:in `with_transaction_returning_status' /Users/nate/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2/lib/active_record/persistence.rb:633:in `update!' ```Gut feeling:
I don't have a good grasp of what the gem is trying to accomplish in that method but, it seems like I'm only getting in that method because:
id: 12459
) must setrow_order
to be before elementid: 12470
(which has row_order-2147483646
), so it must end up being-2147483647
or-2147483648
.id: 12462
) must do the same thing, and would probably need row_order-2147483648
or below which is theMIN_RANK_VALUE
, which probably triggers the call torebalance_ranks
current_order
does not have the currentinstance
soorigin
isnil
, and we get the crash at the comparison=> I feel like the fix might be something along the lines of:
current_order
when the scope is changing at the same time.origin.nil?
origin.to_i
to getnil => 0
, or maybe it should take a higher value than destination then? Not quite sure.Anyways I hope this is clear enough and helpful, let me know if you'd like more information or clarification.
Thank you 🙏