ActiveRecord::AssociationTypeMismatch (Article(#69835604302140) expected, got Article(#69835603825080))
Hi,
My project has an Article model which behaves as ordered tree supported by closure_tree.
Recently when creating new models, it reports the following error, does anyone meet them before?
Started POST "/articles" for 127.0.0.1 at 2017-05-24 02:00:38 +0800
Processing by ArticlesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ETX26zVwht+78Rb0XjCieOfMqipnWMQOi1sCcWXNqNg=", "article"=>{"title"=...
...
INSERT INTO "articles" ("body"...
...
SELECT pg_try_advisory_lock(1396095756,0) AS tc246088da827c93e07b309449ae083d5
SELECT pg_advisory_unlock(1396095756,0) AS tba8edd90f04ff74cfb4203ec7535c563
ROLLBACK
Completed 500 Internal Server Error in 39ms
ActiveRecord::AssociationTypeMismatch (Article(#69835604302140) expected, got Article(#69835603825080)):
app/controllers/articles_controller.rb:152:in `block in create'
app/controllers/articles_controller.rb:151:in `create'
This error looks like randomly occur. Currently I can't reproduce it locally, but does anyone meet it before?
Another question is why it tries to lock article_hierarchies when the parent_id is going to be set as nil? In a successful ArticleController#create, after LOCK is granted it tries to update articles.section_number which is tree order, but why? (it is a root node!). The sequence of LOCK/updateSectionNumber/UNLOCK will disappear if an "after_create" callback is registered to re-save with some other column updated, this also looks strange to me.
I'm using closure_tree 5.2.0, rails 4.2.7.
Any clue to debug?
Thanks in advance. Brian