Skip to content
This repository has been archived by the owner on Apr 10, 2023. It is now read-only.

Broken issue copy functionality #228

Open
martincizek opened this issue May 3, 2021 · 2 comments · May be fixed by #229
Open

Broken issue copy functionality #228

martincizek opened this issue May 3, 2021 · 2 comments · May be fixed by #229

Comments

@martincizek
Copy link

When an issue with children is copied, the parent-child relation is lost.

Steps to reproduce:

  • Install redmine_tags
  • Create issue A with child issue B
  • Use "Copy" on issue A and submit
  • New issues A2 and B2 are created, but A2 is not a parent of B2

This issue is also detected by two of core Redmine tests:

  1. Error:
    IssuesControllerTest#test_create_as_copy_to_a_different_project_should_copy_subtask_custom_fields:
    ActiveRecord::StaleObjectError: Attempted to update a stale object: Issue.
        app/models/issue.rb:222:in `create_or_update'
        plugins/redmine_tags/lib/redmine_tags/hooks/model_issue_hook.rb:18:in `controller_issues_new_after_save'
        lib/redmine/hook.rb:66:in `block (2 levels) in call_hook'
        lib/redmine/hook.rb:66:in `each'
        lib/redmine/hook.rb:66:in `block in call_hook'
        lib/redmine/hook.rb:63:in `tap'
        lib/redmine/hook.rb:63:in `call_hook'
        lib/redmine/hook.rb:96:in `call_hook'
        app/controllers/issues_controller.rb:150:in `create'
        lib/redmine/sudo_mode.rb:61:in `sudo_mode'
        test/functional/issues_controller_test.rb:5383:in `block in test_create_as_copy_to_a_different_project_should_copy_subtask_custom_fields'
        test/functional/issues_controller_test.rb:5382:in `test_create_as_copy_to_a_different_project_should_copy_subtask_custom_fields'
    
    
    bin/rails test test/functional/issues_controller_test.rb:5378
    
  2. Error:
    IssuesControllerTest#test_create_as_copy_should_copy_subtasks:
    ActiveRecord::StaleObjectError: Attempted to update a stale object: Issue.
        app/models/issue.rb:222:in `create_or_update'
        plugins/redmine_tags/lib/redmine_tags/hooks/model_issue_hook.rb:18:in `controller_issues_new_after_save'
        lib/redmine/hook.rb:66:in `block (2 levels) in call_hook'
        lib/redmine/hook.rb:66:in `each'
        lib/redmine/hook.rb:66:in `block in call_hook'
        lib/redmine/hook.rb:63:in `tap'
        lib/redmine/hook.rb:63:in `call_hook'
        lib/redmine/hook.rb:96:in `call_hook'
        app/controllers/issues_controller.rb:150:in `create'
        lib/redmine/sudo_mode.rb:61:in `sudo_mode'
        test/functional/issues_controller_test.rb:5358:in `block in test_create_as_copy_should_copy_subtasks'
        test/functional/issues_controller_test.rb:5357:in `test_create_as_copy_should_copy_subtasks'
    
    
    bin/rails test test/functional/issues_controller_test.rb:5353
    
@martincizek
Copy link
Author

A no-brainer fix would be as follows it works.

diff --git a/lib/redmine_tags/hooks/model_issue_hook.rb b/lib/redmine_tags/hooks/model_issue_hook.rb
index 4eb157f..abbc964 100755
--- a/lib/redmine_tags/hooks/model_issue_hook.rb
+++ b/lib/redmine_tags/hooks/model_issue_hook.rb
@@ -16,4 +16,8 @@ module RedmineTags
       def controller_issues_new_after_save(context = {})
         save_tags_to_issue context, false
         context[:issue].save
+      rescue ActiveRecord::StaleObjectError
+        context[:issue].reload
+        save_tags_to_issue context, false
+        context[:issue].save
       end

But it seems that the problematic controller_issues_new_after_save method is no more needed, so it would be wiser to remove it.

martincizek added a commit to orchitech/redmine_tags that referenced this issue May 3, 2021
@iquiw
Copy link

iquiw commented Dec 7, 2021

I got similar error and PR #229 fixes it. Thanks!!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants