Defect #33914
closedEven if the default value of Activities (time tracking) is set, it may not be reflected.
0%
Description
How to reproduce the problem:
1. bundle exec rake db:fixtures:load
2. Open /projects/ecookbook/time_entries/new and you can see that "Development" is the default Activity choice.
3. Go to /projects/ecookbook/settings/activities and click Save button. At this time TimeEntryActivity.count changes from 4 to 8.
4. When you open /projects/ecookbook/time_entries/new, the default Activity choice is "--- Please select ---".
If you click the Save button in /projects/ecookbook/settings/activities, project-specific activity data will be created based on the original activity data.
If the underlying activity data is the default, then the project-specific activity data based on it should also be the default.
Files
Updated by Mizuki ISHIKAWA about 4 years ago
- File fix-33914.patch fix-33914.patch added
I attach the patch.
Updated by Mizuki ISHIKAWA over 2 years ago
Is it hard to commit to this patch?
I can improve the patch if there are any problems.
Updated by Marius BĂLTEANU over 2 years ago
- Assignee set to Marius BĂLTEANU
- Target version set to 4.2.7
Updated by Marius BĂLTEANU over 2 years ago
- Status changed from Confirmed to Resolved
- Resolution set to Fixed
Updated by Holger Just over 2 years ago
In TimeEntryActivity.default
, all of the project's activities are already loaded from the database in the if
statement. As such, the trailing find_by
is redundant and should be replaced by Ruby-only filtering to avoid running another SQL query to load data we already have.
The trailing line of that method could thus be replaced by the following code with matching behavior to avoid the additional SQL query:
project.activities.detect { |activity| activity.parent_id == default_activity.id }
Also, it is not guaranteed that we have any default activity at all as admins could deselect the default flag on all activities. Thus would result in the super
call to return nil
which in turn would result in an exception in the final line of the overwritten default
method. As such, we also have to check for default_activity.nil?
. The following method should address both of my points:
def self.default(project=nil)
default_activity = super()
if default_activity.nil? || project.nil? || project.activities.blank? || project.activities.include?(default_activity)
return default_activity
end
project.activities.detect { |activity| activity.parent_id == default_activity.id }
end
Updated by Marius BĂLTEANU over 2 years ago
- Status changed from Resolved to Closed
Thanks Holger for your quick review on this. I've committed both patches.