Defect #6579

tree hierachy (lft and rgt) being currupted on (accidentally) multiple submissions of an issue

Added by Bruno Medeiros over 2 years ago. Updated about 1 month ago.

Status:NewStart date:2010-10-05
Priority:HighDue date:
Assignee:-% Done:

0%

Category:Issues
Target version:Candidate for next minor release
Affected version:1.0.2 Resolution:

Description

Frequently some user can accidentally press the 'Create' button twice (or more times) when creating a new subtask. In this case, not only the issue will be created a lot of times, but the issue tree will be corrupted.

I guess the insertion is being done without transaction isolation, and the lft and rgt fields are being calculated in the wrong conditions.

Although the bug reproduction depends on certain conditions, it's easy to reproduce it:
1. Press 'Add' to add some subtask to a existing issue
2. Fill some data in the new subtask
3. Press the 'Create' button a lot of times quickly, without wait the submit's end

After that, there will be some issues as grandson issues (not children issues as expected), but the parent task will be the right one.

I created a example of this problem on the redmine demo, at http://demo.redmine.org/issues/33583
All subtasks 'dd' in this example should be child of parent, but it's not this way.

I'm marking this as High priority because it corrupts the database without an easy fix.


Related issues

Related to Defect #7666: Deleting multiple subtasks brokes nested set hierarchy New 2011-02-20
Related to Defect #6143: Subtask creation form submission race? New 2010-08-16
Related to Defect #8537: Error in copying projects New 2011-06-06
Related to Defect #8157: Redmine do not send notification emails if a recipients e... New
Duplicated by Defect #11772: Multiple parent task - maybe bug? Closed

History

#1 Updated by Bruno Medeiros over 2 years ago

One more info:
The problem is even worse, because after one wrong submission, all new subtasks will become child of the last child, avoiding the creation of a subtask of the parent for ever.

#2 Updated by Mischa The Evil over 2 years ago

As visible on the demo I've been able to reproduce the described behaviour there.
I don't know though if it's something that should be fixed inside Redmine. This seems more of an issue that might affect more Rails-based apps. Though I might be wrong here... 8-)

#3 Updated by Bruno Medeiros over 2 years ago

There's a simple fix to this, as did in #6826:

Disable 'Add' button after click!

#4 Updated by Andrew Vit over 2 years ago

I can have a look at this later today since I worked on #6826.

#5 Updated by Etienne Massip about 2 years ago

  • Category set to Issues
  • Target version set to Candidate for next minor release

#6 Updated by Bruno Medeiros about 2 years ago

Good to see it could be fixed soon. I can confirm this bug is still present on demo, and created another ticket there to demonstrate the problem:

http://demo.redmine.org/issues/2896

All descendants of 2896 should be children, but they are shown in different (wrong) levels.

As I said above, I believe the fix applied to #6826 can fix this too, without much work. Please post here if you need some help with this.

#7 Updated by Etienne Massip about 2 years ago

I wonder if this may be fixed with a transaction isolation explicit setting somewhere (if there is a transaction) ?

#8 Updated by Bruno Medeiros about 2 years ago

Don't know much about RoR, but at least in Java we're used to make each request have its own transaction, making this approach harder than avoid the double click.

The only downside I see on using the 'avoid double click' solution is if more than one user tries to create children for an issue at the exactly same time, which is very unlikely.

#9 Updated by Etienne Massip about 2 years ago

Well, there is no transaction and 2 successive DML (which explain #7667) : #save does the insert and #after_save => #update_nested_set_attributes does an update of the hierarchy.

Doing a single insert (that is, do not call #update_nested_set_attributes after save but before) can be buggy too.

Edit May, 11th : Actually, there is a transaction managed by RoR ActiveRecord.

#10 Updated by Alfredo Bonilla about 2 years ago

Hi, we have this problem in our installation too. Our "work around", re-create the task (duplicate) and re-do the parent relationship.
Here is part of the dump:

  app/models/issue.rb:442:in `soonest_start'
  /var/lib/gems/1.8/gems/ruby-ole-1.2.11.1/lib/ole/support.rb:40:in `send'
  /var/lib/gems/1.8/gems/ruby-ole-1.2.11.1/lib/ole/support.rb:40:in `to_proc'
  app/models/issue.rb:442:in `soonest_start'
  app/models/issue.rb:272:in `validate'
  app/models/issue.rb:498:in `save_issue_with_child_records'
  app/models/issue.rb:487:in `save_issue_with_child_records'

#11 Updated by Vasili Pupkin about 2 years ago

Hi, we have this problem too. My question is - can I manually set the lft/rgt values directly in DB instead of the copying the issues and recreating the hierarchy? What will be the proper values for lft/rgt and for what these columns are defined?

#12 Updated by Bruno Medeiros about 2 years ago

Yes, you can do it, but need to take care. you should do a backup first just in case.

lft and rgt tell redmine how it should build the tree. They hold the visit and unvisit index on a depth-first search on the tree. Example:

  • Parent (lft 1, rgt 10)
    • Child 1 (lft 2, rgt 3)
    • Child 2 (lft 4, rgt 9)
      • Grandson 1 (lft 5, rgt 6)
      • Grandson 2 (lft 7, rgt 8)

Parent is the first to be visited (lft=1), and the last to be unvisited (rgt=10), and so on... These should be calculated for all tickets with the same root. The root will have always lft=1 and rgt = #tickets * 2.

#13 Updated by Luis Serrano Aranda almost 2 years ago

This also happens when copying a project

#14 Updated by Luis Serrano Aranda almost 2 years ago

This it's a workaround...

#8537

This solves part of the problem, but pressing the back button and redo the operation

#16 Updated by Gary Shi over 1 year ago

Just met this problem in my environment (1.2.1). Surprised it's not fixed for such a long time.

If it's so hard to fix, is there any scripts that could fix or recalculate lft/rgt values after a curruption?

#17 Updated by Etienne Massip over 1 year ago

Gary Shi wrote:

(...) is there any scripts that could fix or recalculate lft/rgt values after a curruption?

Try to run

ruby script/runner -e production 'Project.rebuild!'

from your Redmine base directory.

Edit: I mean Issue.rebuild! but didn't try yet so I advise you to make a DB dump before.

#18 Updated by Matt Brown about 1 year ago

I found it possible to reset the parent/child relationships with:

UPDATE `redmine`.`projects` SET lft = 2 * id - 1, rgt = 2 * id;

Then adjust the subprojects relationship manually within the UI.

This will make each of the projects have no parents and no subordinates (as their left [bookend] and right [bookend] are just one number apart).

Knowing this is how the relationship is derived, should allow you to isolate problems more easily. You can actually remove sub-projects just by not having a lft and rgt number within a parent project's lft-rgt range.

I worked hard to migrate from 0.8.4 to 1.3.1 and had to deal directly with the DBs where this situation came into play.

#19 Updated by Eugene Hutorny 12 months ago

Hit this issue with the following scenario:
Two users concurrently update two different issues and assign the same parent id to both of them.
Hierarchy of the parent task becomes broken and access to its children may cause process hanging or crashing.

SQL for detecting broken hierarchies:

select distinct parent_id
from issues 
where parent_id is not null
group by parent_id, rgt 
having count(*) > 1

#20 Updated by Bruno Medeiros 11 months ago

It seems to be fixed after #6555. I couldn't reproduce anymore on demo: http://demo.redmine.org/projects/test6579

Someone could review it and mark as fixed?

#21 Updated by Dani Leni 10 months ago

"Parent task translation missing: en, activerecord, errors, models, issue, attributes, parent_issue_id, not_a_valid_parent"

I think I still got the issue.
Not sure how its produced.

Happens when trying to update subtask.

Version: Redmine 1.3.2.stable

#22 Updated by Andrey Tatarnikov 7 months ago

I think I'm getting same issue with redmine 2.1.2.
I've posted this topic to the board: http://www.redmine.org/boards/2/topics/33878
Sory if I did something wrong.

#23 Updated by Antoine Beaupré about 1 month ago

Note that this also affects projects on Redmine 1.4.

The workaround is to run:

X_DEBIAN_SITEID=koumbit RAILS_ENV=production  ./script/runner 'Project.rebuild!'

(X_DEBIAN_SITEID= is a local hack in the debian package.) This will rebuild the lft and rgt columns that are corrupted. It may mean that the order of projects changes, but the parent/child relationship will stay.

Also available in: Atom PDF