gtt-project / redmine_custom_fields_groups

Redmine plugin for grouping custom fields.
GNU General Public License v3.0
12 stars 5 forks source link

Deleting a custom field which is used in custom fields group is failed #22

Closed sanak closed 5 months ago

sanak commented 6 months ago

Problem Deleting a custom field which is used in custom fields group is failed.

Rails log details ``` Started DELETE "/custom_fields/2" for 127.0.0.1 at 2024-04-09 16:19:53 +0900 Processing by CustomFieldsController#destroy as HTML Parameters: {"authenticity_token"=>"YwLENT7yyZk673OPHLhtELBgmxdsBzeGzPhwR3qibh0cu8f5i1HIaZQKUK1TWMMJmAKQmygQHCT4csP+AtxHog==", "id"=>"2"} (2.1ms) SELECT MAX("tokens"."updated_on") FROM "tokens" WHERE "tokens"."user_id" = $1 AND "tokens"."value" = $2 AND "tokens"."action" = $3 [["user_id", 1], ["value", "92cf39907dffaa6604326d3ecef27279bad6343c"], ["action", "session"]] ↳ app/models/user.rb:478:in `verify_session_token' (1.5ms) SELECT MAX("settings"."updated_on") FROM "settings" ↳ app/models/setting.rb:280:in `check_cache' User Load (1.4ms) SELECT "users".* FROM "users" WHERE "users"."type" IN ($1, $2) AND "users"."status" = $3 AND "users"."id" = $4 LIMIT $5 [["type", "User"], ["type", "AnonymousUser"], ["status", 1], ["id", 1], ["LIMIT", 1]] ↳ app/controllers/application_controller.rb:117:in `find_current_user' Current user: admin (id=1) CustomField Load (0.6ms) SELECT "custom_fields".* FROM "custom_fields" WHERE "custom_fields"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]] ↳ app/controllers/custom_fields_controller.rb:109:in `find_custom_field' TRANSACTION (1.9ms) BEGIN ↳ app/controllers/custom_fields_controller.rb:85:in `destroy' CustomFieldEnumeration Destroy (1.5ms) DELETE FROM "custom_field_enumerations" WHERE "custom_field_enumerations"."id" IN (SELECT "custom_field_enumerations"."id" FROM "custom_field_enumerations" WHERE "custom_field_enumerations"."custom_field_id" = $1 ORDER BY "custom_field_enumerations"."position" ASC) [["custom_field_id", 2]] ↳ app/controllers/custom_fields_controller.rb:85:in `destroy' CustomValue Destroy (1.3ms) DELETE FROM "custom_values" WHERE "custom_values"."custom_field_id" = $1 [["custom_field_id", 2]] ↳ app/controllers/custom_fields_controller.rb:85:in `destroy' IssueCustomField::HABTM_Trackers Destroy (1.8ms) DELETE FROM "custom_fields_trackers" WHERE "custom_fields_trackers"."custom_field_id" = $1 [["custom_field_id", 2]] ↳ app/controllers/custom_fields_controller.rb:85:in `destroy' IssueCustomField::HABTM_Projects Destroy (0.3ms) DELETE FROM "custom_fields_projects" WHERE "custom_fields_projects"."custom_field_id" = $1 [["custom_field_id", 2]] ↳ app/controllers/custom_fields_controller.rb:85:in `destroy' CustomField::HABTM_Roles Destroy (1.1ms) DELETE FROM "custom_fields_roles" WHERE "custom_fields_roles"."custom_field_id" = $1 [["custom_field_id", 2]] ↳ app/controllers/custom_fields_controller.rb:85:in `destroy' IssueCustomField Destroy (8.9ms) DELETE FROM "custom_fields" WHERE "custom_fields"."id" = $1 [["id", 2]] ↳ app/controllers/custom_fields_controller.rb:85:in `destroy' TRANSACTION (0.3ms) ROLLBACK ↳ app/controllers/custom_fields_controller.rb:85:in `destroy' Redirected to http://localhost:3000/custom_fields?tab=IssueCustomField Completed 302 Found in 85ms (ActiveRecord: 41.0ms | Allocations: 11177) ```
PostgreSQL message ```sql DELETE FROM "custom_fields" WHERE "custom_fields"."id" = 2; ``` ``` ERROR: update or delete on table "custom_fields" violates foreign key constraint "fk_rails_dc9da07f56" on table "custom_fields_group_fields" DETAIL: Key (id)=(2) is still referenced from table "custom_fields_group_fields". SQL state: 23503 ```

To Reproduce

  1. Add a custom field to a custom fields group.
  2. Delete the custom field.

Expectation Deleting a custom field should be possible.

sanak commented 5 months ago

Close this because PR:#26 was merged.