Skip to content
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

Custom's field data erase when sorting the issue #27

Open
Sab0tag3d opened this issue May 2, 2022 · 5 comments
Open

Custom's field data erase when sorting the issue #27

Sab0tag3d opened this issue May 2, 2022 · 5 comments

Comments

@Sab0tag3d
Copy link

Summary

Custom's field data erase when sorting the issue

Description

When I create an issue with custom fields and sort it after that (move with sort arrows) the customs fields are erasing.
But the main description field is saving.

Environment

Redmine version 4.2.3.stable
Ruby version 2.7.0-p0 (2019-12-25) [x86_64-linux-gnu]
Rails version 5.2.6
Environment production
Database adapter Mysql2
Mailer queue ActiveJob::QueueAdapters::AsyncAdapter
Mailer delivery smtp
SCM:
Git 2.25.1
Filesystem
Redmine plugins:
redmine_issue_templates 1.1.0
redmine_resources 1.0.6

Visual Proof / Screenshot

screenshot1
Screenshot2
screenshot3

I didn't find any useful info in the logs. But I had noticed that every time I do sorting, I get a new "updated" time. Probably, it correctly replaces the Description field, but customs fields just rewrite with empty data.

@akiko-pusu
Copy link

Did you run the migration task?

See:
https://github.com/agileware-jp/redmine_issue_templates#100

Please inform your schema version of redmine_issue_templates.

select * from schema_migrations where version like '%redmine_issue_templates%';

It would also be very helpful if you could attach some of the Redmine logs from when you submitted the form, especially when you submitted it in development mode.
Such information would be very useful for maintainers and users.

@Sab0tag3d
Copy link
Author

Hi! Thanks for the answer.
Yes, I ran the mitigation task.

schema version:

MariaDB [redmine_default]> select * from schema_migrations where version like '%redmine_issue_templates%';
+----------------------------------------+
| version                                |
+----------------------------------------+
| 1-redmine_issue_templates              |
| 2-redmine_issue_templates              |
| 20121208150810-redmine_issue_templates |
| 20130630141710-redmine_issue_templates |
| 20130701024625-redmine_issue_templates |
| 2014020191500-redmine_issue_templates  |
| 20140307024626-redmine_issue_templates |
| 20140312054531-redmine_issue_templates |
| 20140330155030-redmine_issue_templates |
| 20160727222420-redmine_issue_templates |
| 20160828190000-redmine_issue_templates |
| 20160829001500-redmine_issue_templates |
| 20160829001530-redmine_issue_templates |
| 20170317082100-redmine_issue_templates |
| 20181104065200-redmine_issue_templates |
| 20190303082102-redmine_issue_templates |
| 20190714171020-redmine_issue_templates |
| 20190714211530-redmine_issue_templates |
| 20200101204020-redmine_issue_templates |
| 20200101204220-redmine_issue_templates |
| 20200102204815-redmine_issue_templates |
| 20200102205044-redmine_issue_templates |
| 20200103213630-redmine_issue_templates |
| 20200115073600-redmine_issue_templates |
| 20200314132500-redmine_issue_templates |
| 20200405115700-redmine_issue_templates |
| 20200405120700-redmine_issue_templates |
| 20200418114157-redmine_issue_templates |
| 3-redmine_issue_templates              |
| 4-redmine_issue_templates              |
+----------------------------------------+
30 rows in set (0.001 sec)

Here is the log when I submit the form:

Started GET "/redmine/global_issue_templates/new" for 127.0.0.1 at 2022-05-04 10:04:27 +0200
Processing by GlobalIssueTemplatesController#new as HTML
  Current user: admin (id=1)
  Rendering plugins/redmine_issue_templates/app/views/global_issue_templates/new.html.erb within layouts/base
  Rendered plugins/redmine_issue_templates/app/views/global_issue_templates/_form.html.erb (12.8ms)
  Rendered plugins/redmine_issue_templates/app/views/global_issue_templates/new.html.erb within layouts/base (15.7ms)
Completed 200 OK in 36ms (Views: 25.3ms | ActiveRecord: 5.6ms)
Started GET "/redmine/issue_templates/load_selectable_fields?tracker_id=1&template_id=" for 127.0.0.1 at 2022-05-04 10:04:42 +0200
Processing by IssueTemplatesController#load_selectable_fields as */*
  Parameters: {"tracker_id"=>"1", "template_id"=>""}
  Current user: admin (id=1)
  Rendering text template
  Rendered text template (0.0ms)
Completed 200 OK in 47ms (Views: 0.6ms | ActiveRecord: 5.2ms)
Started POST "/redmine/global_issue_templates" for 127.0.0.1 at 2022-05-04 10:05:03 +0200
Processing by GlobalIssueTemplatesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"GOJej7hf7IussssssnY7jijdPgNRDRcCzynPUwFg3O5/cjF4oXR+INpOMnJcF1sFssssssqsk2F/1g==", "global_issue_template"=>{"title"=>"test-test-test", "tracker_id"=>"1", "issue_title"=>"test-test-test", "description"=>"test-test-test", "builtin_fields"=>"{\"issue_custom_field_values_3\":\"test-test-test\",\"issue_custom_field_values_4\":\"test-test-test\",\"issue_custom_field_values_5\":\"test-test-test\"}", "note"=>"", "related_link"=>"", "link_title"=>"", "is_default"=>"0", "enabled"=>"1", "project_ids"=>[""]}, "commit"=>"Create"}
  Current user: admin (id=1)
Redirected to https://rm.example.com/redmine/global_issue_templates/36
Completed 302 Found in 25ms (ActiveRecord: 13.5ms)
Started GET "/redmine/global_issue_templates/36" for 127.0.0.1 at 2022-05-04 10:05:03 +0200
Processing by GlobalIssueTemplatesController#show as HTML
  Parameters: {"id"=>"36"}
  Current user: admin (id=1)
  Rendering plugins/redmine_issue_templates/app/views/global_issue_templates/show.html.erb within layouts/base
  Rendered plugins/redmine_issue_templates/app/views/global_issue_templates/_form.html.erb (9.6ms)
  Rendered plugins/redmine_issue_templates/app/views/global_issue_templates/show.html.erb within layouts/base (13.1ms)
Completed 200 OK in 47ms (Views: 31.5ms | ActiveRecord: 6.0ms)

It creates a new record in the database, in the table "global_issue_templates". Column "builtin_fields_json" have our "custom fields" data:

--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
issue_custom_field_values_3: test-test-test
issue_custom_field_values_4: test-test-test
issue_custom_field_values_5: test-test-test

And when I moving it:

Started PUT "/redmine/global_issue_templates/36" for 127.0.0.1 at 2022-05-04 10:07:48 +0200
Processing by GlobalIssueTemplatesController#update as JS
  Parameters: {"global_issue_template"=>{"position"=>"34"}, "id"=>"36"}
  Current user: admin (id=1)
Completed 200 OK in 12ms (ActiveRecord: 5.6ms)

After then data in column "builtin_fields_json" became NULL. I think somehow the sorting function ignores this column and just erases it.

@Sab0tag3d
Copy link
Author

I found how to enable debug logs, and it confirms my thoughts. Here is the sorting request:

Started PUT "/redmine/global_issue_templates/36" for 127.0.0.1 at 2022-05-04 10:28:47 +0200
Processing by GlobalIssueTemplatesController#update as JS
  Parameters: {"global_issue_template"=>{"position"=>"36"}, "id"=>"36"}
  Token Update All (1.2ms)  UPDATE `tokens` SET `tokens`.`updated_on` = '2022-05-04 10:28:47' WHERE `tokens`.`user_id` = 1 AND `tokens`.`value` = '9b55a8665c8069cssssssaadf0ecd25fd014648f5' AND `tokens`.`action` = 'session'
   (0.2ms)  SELECT MAX(`settings`.`updated_on`) FROM `settings`
  User Load (0.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)
  GlobalIssueTemplate Load (0.2ms)  SELECT  `global_issue_templates`.* FROM `global_issue_templates` WHERE `global_issue_templates`.`id` = 36 LIMIT 1
   (0.1ms)  BEGIN
  Tracker Load (0.2ms)  SELECT  `trackers`.* FROM `trackers` WHERE `trackers`.`id` = 1 LIMIT 1
  GlobalIssueTemplate Exists (0.3ms)  SELECT  1 AS one FROM `global_issue_templates` WHERE `global_issue_templates`.`title` = BINARY 'test-test-test' AND `global_issue_templates`.`id` != 36 AND `global_issue_templates`.`tracker_id` = 1 LIMIT 1
  GlobalIssueTemplate Update (0.2ms)  UPDATE `global_issue_templates` SET `position` = 36, `builtin_fields_json` = NULL, `updated_on` = '2022-05-04 10:28:47' WHERE `global_issue_templates`.`id` = 36
  GlobalIssueTemplate Update All (0.3ms)  UPDATE `global_issue_templates` SET position = position + -1 WHERE `global_issue_templates`.`tracker_id` = 1 AND (id <> 36 AND position BETWEEN 34 AND 36)
   (1.0ms)  COMMIT
Completed 200 OK in 13ms (ActiveRecord: 4.0ms)

@akiko-pusu
Copy link

@Sab0tag3d Thank you for the information above!
Personally, I think this will be enough to investigate this issue.

And I think this change will be effective.

diff --git a/app/controllers/concerns/issue_templates_common.rb b/app/controllers/concerns/issue_templates_common.rb
index 2b50b1d..0f73c78 100644
--- a/app/controllers/concerns/issue_templates_common.rb
+++ b/app/controllers/concerns/issue_templates_common.rb
@@ -55,6 +55,7 @@ module IssueTemplatesCommon
   end

   def valid_params
+    return template_params unless template_params.has_key?(:builtin_fields)
     attributes = template_params.except(:builtin_fields)
     attributes[:builtin_fields_json] = builtin_fields_json if builtin_fields_enabled?
     attributes

Could you please try it?

By the way, since I am no longer the maintainer and this repository is open to all, I would be very happy to create a pull request for this issue if you think this feature would be useful.
I believe all repository participants would welcome it.

@Sab0tag3d
Copy link
Author

Great job. Thanks!! It fixed.

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

No branches or pull requests

2 participants