MayamaTakeshi / redmine_rt

Redmine plugin for Real-Time notification of events
GNU General Public License v3.0
24 stars 4 forks source link

Add notes fails if plugin redmine_checklists 3.1.21 is present #43

Closed MayamaTakeshi closed 1 year ago

MayamaTakeshi commented 1 year ago

This doesn't happen with latest redmine_checklists 3.1.22.

The GUI shows a window with:

Operation failed

The operation has failed. Please try again after reloading this page.

The redmine debug logs show:

Channel is transmitting the subscription confirmation                                                                                                                        [222/1995]
Channel is streaming from issue:51                                                                                                                                                     
Started PUT "/issues/51/add_quick_notes" for 192.168.181.113 at 2023-11-10 17:18:13 +0900                                                                                              
Processing by IssuesController#add_quick_notes as TEXT                                                                                                                                 
  Parameters: {"issue"=>{"notes"=>"aaa", "private_notes"=>true}, "id"=>"51"}                                                                                                           
  Token Update All (1.6ms)  UPDATE `tokens` SET `tokens`.`updated_on` = '2023-11-10 17:18:13' WHERE `tokens`.`user_id` = 1 AND `tokens`.`value` = 'bff94751612e6575b7484335fa24f585fcc6
ef73' AND `tokens`.`action` = 'session'                                                                                                                                                
   (0.4ms)  SELECT MAX(`settings`.`updated_on`) FROM `settings`                                                                                                                        
  User Load (0.4ms)  SELECT  `users`.* FROM `users` WHERE `users`.`type` IN ('User', 'AnonymousUser') AND `users`.`status` = 1 AND `users`.`id` = 1 LIMIT 1                            
  Current user: admin (id=1)                                                                                                                                                           
  Issue Load (0.4ms)  SELECT  `issues`.* FROM `issues` WHERE `issues`.`id` = 51 LIMIT 1                                                                                                
  Project Load (0.4ms)  SELECT  `projects`.* FROM `projects` WHERE `projects`.`id` = 2 LIMIT 1                                                                                         
   (0.4ms)  SELECT `enabled_modules`.`name` FROM `enabled_modules` WHERE `enabled_modules`.`project_id` = 2                                                                            
  TimeEntryActivity Load (0.4ms)  SELECT  `enumerations`.* FROM `enumerations` WHERE `enumerations`.`type` IN ('TimeEntryActivity') AND `enumerations`.`is_default` = TRUE ORDER BY `en
umerations`.`position` ASC LIMIT 1                                                                                                                                                     
  Tracker Load (0.3ms)  SELECT  `trackers`.* FROM `trackers` WHERE `trackers`.`id` = 3 LIMIT 1                                                                                         
  IssueCustomField Load (0.6ms)  SELECT `custom_fields`.* FROM `custom_fields` WHERE `custom_fields`.`type` IN ('IssueCustomField') AND (is_for_all = TRUE OR id IN (SELECT DISTINCT cf
p.custom_field_id FROM custom_fields_projects cfp WHERE cfp.project_id = 2)) ORDER BY `custom_fields`.`position` ASC                                                                   
  IssueCustomField Load (0.4ms)  SELECT `custom_fields`.* FROM `custom_fields` INNER JOIN `custom_fields_trackers` ON `custom_fields`.`id` = `custom_fields_trackers`.`custom_field_id`
 WHERE `custom_fields`.`type` IN ('IssueCustomField') AND `custom_fields_trackers`.`tracker_id` = 3                                                                                    
  CustomValue Load (0.4ms)  SELECT `custom_values`.* FROM `custom_values` WHERE `custom_values`.`customized_id` = 51 AND `custom_values`.`customized_type` = 'Issue'                   
  CustomField Load (0.4ms)  SELECT `custom_fields`.* FROM `custom_fields` WHERE `custom_fields`.`id` IN (1, 2, 3, 4, 15)                                                               
  IssueStatus Load (0.4ms)  SELECT  `issue_statuses`.* FROM `issue_statuses` WHERE `issue_statuses`.`id` = 2 LIMIT 1                                                                   
  Role Load (0.3ms)  SELECT `roles`.* FROM `roles`                                                                                                                                     
  User Load (0.4ms)  SELECT  `users`.* FROM `users` WHERE `users`.`type` IN ('User', 'AnonymousUser') AND `users`.`id` = 1 LIMIT 1                                                     
  IssueStatus Load (0.7ms)  SELECT DISTINCT `issue_statuses`.* FROM `issue_statuses` INNER JOIN `workflows` ON `workflows`.`new_status_id` = `issue_statuses`.`id` AND `workflows`.`typ
e` IN ('WorkflowTransition') WHERE `workflows`.`old_status_id` = 2 AND `workflows`.`role_id` IN (1, 2, 3, 4, 5) AND `workflows`.`tracker_id` = 3 AND (author = TRUE OR assignee = FALSE
)       
  IssueRelation Load (0.4ms)  SELECT `issue_relations`.* FROM `issue_relations` WHERE `issue_relations`.`issue_to_id` = 51                                                             
  CACHE Role Load (0.0ms)  SELECT `roles`.* FROM `roles`                                                                                                                               
  WorkflowPermission Load (0.7ms)  SELECT `workflows`.* FROM `workflows` WHERE `workflows`.`type` IN ('WorkflowPermission') AND `workflows`.`tracker_id` = 3 AND `workflows`.`old_statu
s_id` = 2 AND `workflows`.`role_id` IN (1, 3, 4, 5)                                                                                                                                    
  CACHE Role Load (0.0ms)  SELECT `roles`.* FROM `roles`                                                                                                                               
  CACHE IssueStatus Load (0.0ms)  SELECT DISTINCT `issue_statuses`.* FROM `issue_statuses` INNER JOIN `workflows` ON `workflows`.`new_status_id` = `issue_statuses`.`id` AND `workflows
`.`type` IN ('WorkflowTransition') WHERE `workflows`.`old_status_id` = 2 AND `workflows`.`role_id` IN (1, 2, 3, 4, 5) AND `workflows`.`tracker_id` = 3 AND (author = TRUE OR assignee =
 FALSE)                                                                                                                                                                                
   (0.2ms)  BEGIN                                                                                                                                                                      
  CACHE Role Load (0.0ms)  SELECT `roles`.* FROM `roles`                                                                                                                               
  CACHE WorkflowPermission Load (0.0ms)  SELECT `workflows`.* FROM `workflows` WHERE `workflows`.`type` IN ('WorkflowPermission') AND `workflows`.`tracker_id` = 3 AND `workflows`.`old
_status_id` = 2 AND `workflows`.`role_id` IN (1, 3, 4, 5)                                                                                                                              
  Setting Load (0.5ms)  SELECT  `settings`.* FROM `settings` WHERE `settings`.`name` = 'plugin_redmine_checklists' ORDER BY `settings`.`id` DESC LIMIT 1                               
  Setting Load (0.4ms)  SELECT  `settings`.* FROM `settings` WHERE `settings`.`name` = 'close_duplicate_issues' ORDER BY `settings`.`id` DESC LIMIT 1                                  
  Issue Update (0.4ms)  UPDATE `issues` SET `updated_on` = '2023-11-10 17:18:13', `lock_version` = 38 WHERE `issues`.`id` = 51 AND `issues`.`lock_version` = 37                        
  Journal Create (0.5ms)  INSERT INTO `journals` (`journalized_id`, `journalized_type`, `user_id`, `notes`, `created_on`, `updated_on`, `private_notes`) VALUES (51, 'Issue', 1, 'aaa',
 '2023-11-10 17:18:13', '2023-11-10 17:18:13', TRUE)                                                                                                                                   
  JournalDetail Load (0.4ms)  SELECT `journal_details`.* FROM `journal_details` WHERE `journal_details`.`journal_id` = 2603                                                            
  Setting Load (0.3ms)  SELECT  `settings`.* FROM `settings` WHERE `settings`.`name` = 'notified_events' ORDER BY `settings`.`id` DESC LIMIT 1                                         
handle_journal_after_create                                                                                                                                                            
  Issue Load (0.3ms)  SELECT  `issues`.* FROM `issues` WHERE `issues`.`id` = 51 LIMIT 1                                                                                                
handle_journal_after_save                                                                                                                                                              
[ActionCable] Broadcasting to issue:51: {:event=>"journal 2603 saved", :type=>"journal_saved", :journal_id=>2603}                                                                      
[ActionCable] Broadcasting to issue:51: {:event=>"issue 51 saved", :type=>"issue_saved", :issue_id=>51}                                                                                
Channel transmitting {"event"=>"journal 2603 saved", "type"=>"journal_saved", "journal_id"=>2603} (via streamed from issue:51)                                                         
  Checklist Load (0.8ms)  SELECT `checklists`.* FROM `checklists` WHERE `checklists`.`issue_id` = 51 ORDER BY checklists.position                                                      
Channel transmitting {"event"=>"issue 51 saved", "type"=>"issue_saved", "issue_id"=>51} (via streamed from issue:51)                                                                   
   (1.3ms)  ROLLBACK                                                                                                                                                                   
Completed 500 Internal Server Error in 66ms (ActiveRecord: 14.2ms)                                                                                                                     

NoMethodError (undefined method `map' for nil:NilClass):                                                                                                                               

plugins/redmine_checklists/app/models/journal_checklist_history.rb:138:in `force_object'                                                                                               
plugins/redmine_checklists/app/models/journal_checklist_history.rb:59:in `initialize'                                                                                                  
plugins/redmine_checklists/lib/redmine_checklists/hooks/controller_issues_hook.rb:27:in `new'                                                                                          
plugins/redmine_checklists/lib/redmine_checklists/hooks/controller_issues_hook.rb:27:in `controller_issues_edit_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:630:in `block in save_issue_with_child_records'                                                                                                   
app/controllers/issues_controller.rb:610:in `save_issue_with_child_records'                                                                                                            
plugins/redmine_rt/lib/redmine_rt/issues_controller_patch.rb:82:in `add_quick_notes'                                                                                                   
lib/redmine/sudo_mode.rb:61:in `sudo_mode'                                                                                                                                             
Started GET "/issues/51" for 192.168.181.113 at 2023-11-10 17:18:13 +0900                                                                                                              
Started GET "/journals/2603?indice=38" for 192.168.181.113 at 2023-11-10 17:18:13 +0900                                                                                                
Processing by IssuesController#show as */*                                                                                                                                             
  Parameters: {"id"=>"51"}                                                                                                                                                             
  Token Update All (3.9ms)  UPDATE `tokens` SET `tokens`.`updated_on` = '2023-11-10 17:18:13' WHERE `tokens`.`user_id` = 1 AND `tokens`.`value` = 'bff94751612e6575b7484335fa24f585fcc6
ef73' AND `tokens`.`action` = 'session'                                                                                                                                                
Processing by JournalsController#show as */*                                                                                                                                           
  Parameters: {"indice"=>"38", "id"=>"2603"}                                                                                                                                           
   (1.2ms)  SELECT MAX(`settings`.`updated_on`) FROM `settings`                                                                                                                        
  User Load (0.6ms)  SELECT  `users`.* FROM `users` WHERE `users`.`type` IN ('User', 'AnonymousUser') AND `users`.`status` = 1 AND `users`.`id` = 1 LIMIT 1                            
  Current user: admin (id=1)                                                                                                                                                           
   (9.5ms)  SET NAMES utf8,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout =
 2147483                                                                                                                                                                               
  Issue Load (7.0ms)  SELECT  `issues`.* FROM `issues` WHERE `issues`.`id` = 51 LIMIT 1                                                                                                
  Token Update All (0.4ms)  UPDATE `tokens` SET `tokens`.`updated_on` = '2023-11-10 17:18:13' WHERE `tokens`.`user_id` = 1 AND `tokens`.`value` = 'bff94751612e6575b7484335fa24f585fcc6
ef73' AND `tokens`.`action` = 'session'                                                                                                                                                
   (2.0ms)  SELECT MAX(`settings`.`updated_on`) FROM `settings`                                                                                                                        
  Project Load (2.8ms)  SELECT  `projects`.* FROM `projects` WHERE `projects`.`id` = 2 LIMIT 1                                                                                         
   (0.5ms)  SELECT `enabled_modules`.`name` FROM `enabled_modules` WHERE `enabled_modules`.`project_id` = 2                                                                            
  Journal Load (1.1ms)  SELECT `journals`.* FROM `journals` WHERE `journals`.`journalized_id` = 51 AND `journals`.`journalized_type` = 'Issue' ORDER BY `journals`.`created_on` ASC, `j
ournals`.`id` ASC                                                                                                                                                                      
  User Load (3.3ms)  SELECT  `users`.* FROM `users` WHERE `users`.`type` IN ('User', 'AnonymousUser') AND `users`.`status` = 1 AND `users`.`id` = 1 LIMIT 1                            
  Current user: admin (id=1)                                                                                                                                                           
  Journal Load (3.2ms)  SELECT  `journals`.* FROM `journals` WHERE `journals`.`id` = 2603 LIMIT 1                                                                                      
Completed 404 Not Found in 38ms (ActiveRecord: 18.4ms)                                                                                                                                 

ActiveRecord::RecordNotFound (Couldn't find Journal with 'id'=2603): 
MayamaTakeshi commented 1 year ago

This was reported on 3.1.21 PRO. The version I have is 3.1.22 Light (FREE) and in it, the code that caused the error is absent:

   module Hooks
     class ControllerIssuesHook < Redmine::Hook::ViewListener
       def controller_issues_edit_after_save(context = {})
-        old_checklists = context[:issue].old_checklists
-        new_checklists = context[:issue].checklists.to_json
-        journal = context[:journal]
-        details = JournalChecklistHistory.new(old_checklists, new_checklists).journal_details
-        if JournalChecklistHistory.can_fixup?(details)
-          JournalChecklistHistory.fixup(details)
-        elsif details.old_value != details.value
-          journal.details << details
-          journal.save
-        else
-          journal.save
-        end

         if (Setting.issue_done_ratio == 'issue_field') && RedmineChecklists.issue_done_ratio?
           Checklist.recalc_issue_done_ratio(context[:issue].id)

I believe the absent code is related to features from the paid (PRO) version. So an upgrade to 3.1.22 PRO is unlikely to solve this issue.

MayamaTakeshi commented 1 year ago

This should have been solved by #44.