-
Notifications
You must be signed in to change notification settings - Fork 241
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
ActiveRecord::RecordNotUnique #285
Comments
I'm having a similar problem and can provide more detail. The application works fine in development using puma to serve the pages. In production we use nginx and passenger. We're using Rails 5.0 and Ruby 2.4.0 on both servers. Both use MySql 5.7.19. Development is a Mac running Sierra 10.12.6 and Production is running Ubuntu 17.04 The problem occurs regardless of the value of with_advisory_lock. When I attempt to move an existing record into a newly created tree, I get the duplicate entry error. If the "existing record"/parent is created in the same transaction as the child, I can clearly see the input into _hierarchies when that is created as well as when the children are created. The problem is that at the end of the transaction, it creates a 2nd record in _hierarchies for the parent. This was also a problem whenever I used Paren.add_child(child). I don't know why there would be a difference, but this was resolved by setting the parent_id for the child before the child is created. Since I'm trying to move an existing record, I can't use this trick. Any suggestions would be greatly appreciated. |
For me the stack trace (reduced to closure tree call) is:
error:
Create:
|
@mceachen So I also figured out that all I need to do to get this to happen is run the same thing with a change of title. # No problem the first time
Tag.find_or_create_by_path([
{name: 'Yup', title: 'Yup'}
])
# Duplicate exception
Tag.find_or_create_by_path([
{name: 'Yup', title: 'Yup'}
]) I also noticed that ClosureTree::Finders#find_by_path checks for the title to be the same when looking for existing tags, even though I suspect it should be only checking for tags with the same |
@gerrywastaken your duplicate exception doesn't isolate an error with # No problem the first time
Tag.find_or_create_by_path([
{name: 'first', title: 'Yup'}
])
# Duplicate exception
Tag.find_or_create_by_path([
{name: 'second', title: 'Yup'}
]) ?
That'd be bad--where do you see that? https://github.com/ClosureTree/closure_tree/blob/master/lib/closure_tree/finders.rb#L136 |
@mceachen Experiencing the same behaviour in our project, why does the |
Hi,
we keep getting this error in our production environment.
eg.
ActiveRecord::RecordNotUnique: Mysql2::Error: Duplicate entry '800291-800291-0' for key 'entry_anc_desc_idx': INSERT INTO
entry_hierarchies
(ancestor_id
,descendant_id
,generations
) VALUES (800291, 800291, 0)Here entry_hierarchies is the hierarchies table. We have tried several solutions and feel that this could be a bug in the gem, let us know if this is an issue
The text was updated successfully, but these errors were encountered: