Skip to content

ActiveRecord::RecordNotFound exception when Deterministic Ordering is used #125

Open
@geordee

Description

@geordee

I recently upgraded the application to Rails 4.1.6 (from 4.1.0) and closure_tree 5.0.0.

I started getting the following error then onwards. If I remove the deterministic ordering, the error goes away.

Note: I do need the results to be pre-ordered.

Loading development environment (Rails 4.1.6)
irb(main):001:0> org1 = Organization.create! name: 'Primary'
ActiveRecord::RecordNotFound: Couldn't find Organization with 'id'=2
  from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/relation/finder_methods.rb:320:in `raise_record_not_found_exception!'
  from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/relation/finder_methods.rb:429:in `find_one'
  from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/relation/finder_methods.rb:413:in `find_with_ids'
  from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/relation/finder_methods.rb:68:in `find'
  from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/querying.rb:3:in `find'
  from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/persistence.rb:394:in `block in reload'
  from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/scoping/default.rb:32:in `block in unscoped'
  from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/relation.rb:292:in `scoping'
  from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/scoping/default.rb:32:in `unscoped'
  from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/persistence.rb:394:in `reload'
  from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/attribute_methods/dirty.rb:36:in `reload'
  from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/autosave_association.rb:219:in `reload'
  from /usr/local/lib/ruby/gems/2.1.0/gems/closure_tree-5.0.0/lib/closure_tree/numeric_deterministic_ordering.rb:21:in `_ct_reorder_siblings'
  from /usr/local/lib/ruby/gems/2.1.0/gems/closure_tree-5.0.0/lib/closure_tree/hierarchy_maintenance.rb:79:in `block in rebuild!'
  from /usr/local/lib/ruby/gems/2.1.0/gems/closure_tree-5.0.0/lib/closure_tree/support.rb:120:in `block (2 levels) in with_advisory_lock'
  from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:199:in `transaction'
... more levels...

I tried stepping through the releases, and found that it works fine in 4.5.0, but not in 4.6.0. Something broke/changed between 4.5.0 and 4.6.0?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions