Project

General

Profile

Actions

Defect #32977

closed

Remove references to deleted user from "user"-Format CustomFields

Added by Jens Krämer almost 5 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Category:
Custom fields
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

When a user record is destroyed, custom field values for custom fields with field_format == 'user' referencing the destroyed user are left unchanged.

This leads to problems with queries on such a custom field when using either the none or any operators, since these match against custom_values.value (not) being null or '' - records that have the destroyed user's ID set will not turn up in the none query, but in the any query, despite being displayed with an empty value in the UI.

The attached patch adds a test case and addresses the issue by removing custom_values records that reference the destroyed user.


Files


Related issues

Has duplicate Redmine - Feature #8443: Removing CustomValue with related User objectClosed2011-05-26

Actions
Actions #1

Updated by Go MAEDA almost 5 years ago

  • Target version set to Candidate for next minor release
Actions #2

Updated by Marius BĂLTEANU almost 5 years ago

We shouldn't add a migration to remove the existing orphaned values?

Actions #3

Updated by Jens Krämer almost 5 years ago

we should indeed do that. I'll take care of that tomorrow.

Actions #4

Updated by Jens Krämer almost 5 years ago

here's a new patch including a migration to delete already existing orphaned values.

Actions #5

Updated by Go MAEDA almost 5 years ago

  • Target version changed from Candidate for next minor release to Candidate for next major release

The patch cannot be committed for minor releases because it has a migration.

Actions #6

Updated by Go MAEDA almost 5 years ago

  • Assignee set to Jean-Philippe Lang
  • Target version changed from Candidate for next major release to 4.2.0

Setting the target version to 4.2.0.

Actions #7

Updated by Marius BĂLTEANU over 3 years ago

  • Target version changed from 4.2.0 to 5.0.0
Actions #8

Updated by Marius BĂLTEANU over 3 years ago

  • Status changed from New to Needs feedback
  • Assignee changed from Jean-Philippe Lang to Jens Krämer

Jens, I've reviewed the patch and it looks good to me, except the test that fails:


➜  redmine git:(patch/32977) ✗ ruby test/unit/user_test.rb -n test_remove_custom_field_references_upon_destroy
Skipping LDAP tests.
Run options: -n test_remove_custom_field_references_upon_destroy --seed 57996

# Running:

F

Failure:
UserTest#test_remove_custom_field_references_upon_destroy [test/unit/user_test.rb:1341]:
#<Proc:0x00007fcf93fa35d8@test/unit/user_test.rb:1341 (lambda)> didn't change by -2.
Expected: 20
  Actual: 19

I think the problem is in the test because the following update:

issue.update(custom_field_values:
{
  cf1.id => @jsmith.id,
  cf2.id => [@dlopper.id, @jsmith.id]
})

generates 3 entries in CustomValue (one for each user) and we should expect 3 less custom values when the user jsmith is destroyed.

diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index e2dec070c..42011f759 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -1336,7 +1336,7 @@ class UserTest < ActiveSupport::TestCase
     assert cv2a = cv2.detect{|cv| cv.value == @dlopper.id.to_s}
     assert cv2b = cv2.detect{|cv| cv.value == @jsmith.id.to_s}

-    assert_difference ->{CustomValue.count}, -2 do
+    assert_difference ->{CustomValue.count}, -3 do
       @jsmith.destroy
     end
Actions #9

Updated by Jens Krämer over 3 years ago

I just tried and it passes here (MySQL 5.6, Ruby 2.6).

Since we delete jsmith (but not dlopper), the custom value for @dlopper should not be affected. I have no clue why the test fails for you though.

Actions #10

Updated by Marius BĂLTEANU about 3 years ago

  • Assignee changed from Jens Krämer to Marius BĂLTEANU

Jens Krämer wrote:

I just tried and it passes here (MySQL 5.6, Ruby 2.6).

Since we delete jsmith (but not dlopper), the custom value for @dlopper should not be affected. I have no clue why the test fails for you though.

Thanks, you're right, user @dlopper should not be affected, I will take again a look. It doesn't fail only on my local environment, it fails also on the custom Gitlab CI.

Actions #11

Updated by Marius BĂLTEANU about 3 years ago

  • Status changed from Needs feedback to New
Actions #12

Updated by Marius BĂLTEANU about 3 years ago

Jens Krämer wrote:

Since we delete jsmith (but not dlopper), the custom value for @dlopper should not be affected. I have no clue why the test fails for you though.

The number of CustomValue decreases with 3 not because of those 3 values that are added during the tests (as I wrongly said first time), but because @jsmith user has also a CustomValue of type User (CustomValue#3) which is deleted as well when user is destroyed.

Jens, it should fail also on your environment if you use the default Redmine fixtures.

I'm going to change the user in the tests and I will commit this fix.

Actions #13

Updated by Marius BĂLTEANU about 3 years ago

  • Status changed from New to Resolved
Actions #14

Updated by Marius BĂLTEANU about 3 years ago

Patch committed, thank you.

I've updated the tests to assert -3 custom values and I added a comment.

Actions #15

Updated by Marius BĂLTEANU about 3 years ago

  • Status changed from Resolved to Closed
Actions #16

Updated by Go MAEDA over 2 years ago

  • Tracker changed from Patch to Defect
Actions #17

Updated by Go MAEDA over 1 year ago

  • Has duplicate Feature #8443: Removing CustomValue with related User object added
Actions

Also available in: Atom PDF