Defect #5354

Updating custom fields does not trigger update to "updated_on" field in the Project model

Added by Stuart Cianos over 7 years ago. Updated over 6 years ago.

Status:NewStart date:2010-04-20
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Custom fields
Target version:-
Resolution: Affected version:0.9.3

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.

redmine_patch_5354.diff Magnifier - Patch to Redmine core which corrects defect (1.09 KB) Stuart Cianos, 2010-05-13 01:15

redmine_patch_5354_r2.diff Magnifier - Patch which corrects the issue against 1.0.1 (1.22 KB) Stuart Cianos, 2010-09-03 19:30

scvmc_project_cf_updated_on_r3.diff Magnifier - Patch which corrects the issue against trunk r4093, using callbacks within model (1017 Bytes) Stuart Cianos, 2010-09-17 02:45

History

#1 Updated by Stuart Cianos over 7 years ago

Patch which corrects the behavior is attached.

#2 Updated by Jean-Baptiste Barth about 7 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 ?

#3 Updated by Stuart Cianos about 7 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 ?

#4 Updated by Stuart Cianos about 7 years ago

New patch revision against Redmine 1.0.1

#5 Updated by Stuart Cianos about 7 years ago

  • Assignee set to Eric Davis

#6 Updated by Holger Just about 7 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.

#7 Updated by Stuart Cianos about 7 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?

#8 Updated by Eric Davis about 7 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.

#9 Updated by Stuart Cianos about 7 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.

#10 Updated by Stuart Cianos about 7 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?

#11 Updated by Toshi MARUYAMA over 6 years ago

  • Category set to Custom fields

Also available in: Atom PDF