Project

General

Profile

Actions

Defect #5354

closed

Updating custom fields does not trigger update to "updated_on" field in the customized object

Added by Stuart Cianos about 14 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Custom fields
Target version:
Start date:
2010-04-20
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

When updating a custom field (which has been defined within the Redmine settings), the updated_on field in the Projects table is not updated to reflect the date of modification to the project's settings.


Files

redmine_patch_5354.diff (1.09 KB) redmine_patch_5354.diff Patch to Redmine core which corrects defect Stuart Cianos, 2010-05-13 01:15
redmine_patch_5354_r2.diff (1.22 KB) redmine_patch_5354_r2.diff Patch which corrects the issue against 1.0.1 Stuart Cianos, 2010-09-03 19:30
scvmc_project_cf_updated_on_r3.diff (1017 Bytes) scvmc_project_cf_updated_on_r3.diff Patch which corrects the issue against trunk r4093, using callbacks within model Stuart Cianos, 2010-09-17 02:45
5354_fixed.patch (1.89 KB) 5354_fixed.patch Yuichi HARADA, 2020-01-20 06:59
5354_fixed_v2.patch (1.83 KB) 5354_fixed_v2.patch Yuichi HARADA, 2020-02-12 04:03
Actions #1

Updated by Stuart Cianos almost 14 years ago

Patch which corrects the behavior is attached.

Actions #2

Updated by Jean-Baptiste Barth over 13 years ago

Sorry I don't see the point : I can confirm updated_on field is not updated when you just change a custom field, but why do you need it to be updated ? I don't see any place where we display or use this information, so it doesn't seem to be a problem to me. Can you explain your use-case please ?

Actions #3

Updated by Stuart Cianos over 13 years ago

The field is used by plugins and reports at our site to determine the last date of activity on the project's general information. It could potentially be used by other plugins or reporting tools as well.

Not updating the field is not the expected behavior to end users, and would be considered a bug if a user is expecting the updated_on value to actually reflect the last date of update for the project's general information (whether native or a custom field).

- Stu

Jean-Baptiste Barth wrote:

Sorry I don't see the point : I can confirm updated_on field is not updated when you just change a custom field, but why do you need it to be updated ? I don't see any place where we display or use this information, so it doesn't seem to be a problem to me. Can you explain your use-case please ?

Actions #4

Updated by Stuart Cianos over 13 years ago

New patch revision against Redmine 1.0.1

Actions #5

Updated by Stuart Cianos over 13 years ago

  • Assignee set to Eric Davis
Actions #6

Updated by Holger Just over 13 years ago

  • Assignee deleted (Eric Davis)

Please don't assign issues to people without them telling you to do so explicitly.

Also, your patch has some issues.

  • You save projects two times and don't check the second time.
  • Patches always have to be against trunk to be accepted.
  • You are missing some tests.
Actions #7

Updated by Stuart Cianos over 13 years ago

Bullet points 1 and 2 fixed:

# Force a save of the project record with the correct updated_on time
# to cover corner cases of custom fields, etc. being updated by user
# which do not natively trigger the base project save method
@project.updated_on = Time.now
if validate_parent_id && @project.save
  @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
  flash[:notice] = l(:notice_successful_update)

Before submitting a new patch against Trunk, what specific tests need to be wrapped around setting project.updated_on in order to get this accepted upstream?

Actions #8

Updated by Eric Davis over 13 years ago

Thanks for the patch. You shouldn't set updated_on yourself though. Rails provides a :touch option that will automatically update updated_on when any custom field changes.

http://github.com/rails/rails/commit/abb899c54e8777428b7a607774370ba29a5573bd

Also, your proposed patch would work for editing a project through the web only. If a project is updated any other way, it wouldn't be updated.

Actions #9

Updated by Stuart Cianos over 13 years ago

New patch which handles the update within the custom_value model is attached. Note that I attempted to use the :touch property within the belongs_to in custom_value, but ran into what may be a bug or undefined behavior for polymorphic fields in ActiveRecord (though did not have time to try and debug activerecord itself). I found a way around it by using a callback and then checking if the parent relation was a project.

If there is a better methodology to address this within Redmine's model, please do suggest so that it can be implemented and submitted for inclusion.

Actions #10

Updated by Stuart Cianos over 13 years ago

Quick question: Does the development team prefer that a patch issue be opened up w/ the diff for the refactored patch, or just keep the fix attached to this defect?

Actions #11

Updated by Toshi MARUYAMA about 13 years ago

  • Category set to Custom fields
Actions #12

Updated by shawn freeman over 4 years ago

Bump - I have this problem as well.

Environment:
Redmine version 4.0.2.stable
Ruby version 2.4.5-p335 (2018-10-18) [x86_64-linux]
Rails version 5.2.2
Environment production
Database adapter Mysql2
Mailer queue ActiveJob::QueueAdapters::AsyncAdapter
Mailer delivery sendmail
SCM:
Subversion 1.7.14
Git 2.19.1
Filesystem
Redmine plugins:
redmine_agile 1.4.11
redmine_checklists 3.1.16
redmine_default_custom_query 1.4.0
redmine_image_clipboard_paste 3.3.0
redmineup_tags 2.0.4

Actions #13

Updated by Yuichi HARADA about 4 years ago

Update updated_on of the class (e.g. Project) that uses 'acts_as_customizable' with the following patch.

diff --git a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
index 96fdbf8b6..3703a5e65 100644
--- a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
+++ b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
@@ -145,7 +145,9 @@ module Redmine
             end
           end
           self.custom_values = target_custom_values
+          custom_values_changed = custom_values.any?(&:changed?)
           custom_values.each(&:save)
+          touch if persisted? && custom_values_changed
           @custom_field_values_changed = false
           true
         end
Actions #14

Updated by Go MAEDA about 4 years ago

  • Target version set to Candidate for next major release
Actions #15

Updated by Go MAEDA about 4 years ago

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

Setting the target version to 4.2.0.

Actions #16

Updated by Go MAEDA about 4 years ago

  • Subject changed from Updating custom fields does not trigger update to "updated_on" field in the Project model to Updating custom fields does not trigger update to "updated_on" field in the customized object
Actions #17

Updated by Go MAEDA about 4 years ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patch. Thank you.

Actions #18

Updated by Go MAEDA about 4 years ago

  • Status changed from Closed to Reopened

The patch breaks an existing test.

Failure:
IssueTest#test_closed_on_should_be_set_when_closing_an_open_issue [/var/lib/jenkins/workspace/trunk/DATABASE_ADAPTER/postgresql/RUBY_VER/ruby-2.6/test/unit/issue_test.rb:3071]:
No visible difference in the ActiveSupport::TimeWithZone#inspect output.
You should look at the implementation of #== on ActiveSupport::TimeWithZone or its members.
Tue, 11 Feb 2020 04:40:14 UTC +00:00

bin/rails test test/unit/issue_test.rb:3064
Actions #19

Updated by Yuichi HARADA about 4 years ago

Go MAEDA wrote:

The patch breaks an existing test.

[...]

The test passes with the following patch. The saved_changes? method is available in Rails 5.1.0 and later.
https://github.com/rails/rails/blob/v5.1.0/activerecord/lib/active_record/attribute_methods/dirty.rb#L170
https://github.com/rails/rails/pull/25337

diff --git a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
index 3703a5e65..73b2ae847 100644
--- a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
+++ b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
@@ -145,9 +145,8 @@ module Redmine
             end
           end
           self.custom_values = target_custom_values
-          custom_values_changed = custom_values.any?(&:changed?)
           custom_values.each(&:save)
-          touch if persisted? && custom_values_changed
+          touch if !saved_changes? && custom_values.any?(&:saved_changes?)
           @custom_field_values_changed = false
           true
         end
Actions #20

Updated by Go MAEDA about 4 years ago

  • Status changed from Reopened to Closed

Committed the new patch. Thank you.

Actions

Also available in: Atom PDF