Error 500 when deleting an issue which is sorted in a kanban
Even if I understand it should not happen because you should not delete issues, it still can happen, especially when you are testing how redmine works or you want to clean-up things.
Anyway, it is not normal that it fails with this error.
I had to find modify the kanban options to allow to "un-sort" issues, then un-osrt the issue to delete, then deletion work as expected.
If you sort an issue and try to delete it, it'll end up with a internal server error 500 and you'll find this in production.log:
Started DELETE "/issues/2" for 10.21.1.38 at 2018-03-23 13:41:51 +0100
Processing by IssuesController#destroy as HTML
Parameters: {"authenticity_token"=>"WDXZgE7QA7Votdo1J8fWBCUHkGBx7w+3VrRRydG9uo4ujOnqse5j3fTwY8v2nWwFKjtXaQPH44TM4BbzNlSz8Q==", "id"=>"2"}
Current user: ctxnop (id=6)
Completed 500 Internal Server Error in 652ms (ActiveRecord: 637.9ms)
ActiveRecord::StatementInvalid (Mysql2::Error: Cannot delete or update a parent row: a foreign key constraint fails ('redmine'.'redhopper_issues', CONSTRAINT 'fk_rails_d346a13856' FOREIGN KEY ('issue_id') REFERENCES 'issues' ('id')): DELETE FROM 'issues' WHERE 'issues'.'id' = 2 AND 'issues'.'lock_version' = 7):
app/models/issue.rb:224:in 'destroy'
app/controllers/issues_controller.rb:394:in 'block in destroy'
app/controllers/issues_controller.rb:392:in 'each'
app/controllers/issues_controller.rb:392:in 'destroy'
lib/redmine/sudo_mode.rb:63:in 'sudo_mode'
Two solutions to fix this issue: 1 - Fix the queries to allow deletion of sorted issues 2 - Handle the error and display a message about the reason why you can't delete the issue and how to proceed to do so.
If the second solution is chosen, then I would suggest to switch the default value to ON for the option that allow to un-sort issues.