Project

General

Profile

Actions

Patch #41678

closed

Fix lost backward compatibility about return type of ProjectQuery#results_scope

Added by Nishida Yuya about 2 months ago. Updated about 2 months ago.

Status:
Closed
Priority:
Normal
Category:
Projects
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

Description

r22811 changed return type of ProjectQuery#results_scope : Project::ActiveRecord_Relation => Array of Project instance

That change is no impact for Redmine end users. But it is broken backward compatibility for some Redmine plugins which uses ProjectQuery#results_scope . This patch fixes it.

In addition, UserQuery#results_scope (same name method) still returns User::ActiveRecord_Relation . And TimeEntryQuery#results_scope ditto.

Related issue: #23954


Files


Related issues

Related to Redmine - Feature #23954: Shows the date of the last activity on Projects administrationClosedMarius BĂLTEANU

Actions
Actions #1

Updated by Nishida Yuya about 2 months ago

After apply fix_lost_backward_compatibility_about_return_type_of_ProjectQuery_results_scope.patch , Project.load_last_activity_date 's effect still lives as following:


Apply following patch for check.

diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index f9a390c58..11078d89a 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -335,7 +335,9 @@ def bulk_destroy

   # Returns the ProjectEntry scope for index
   def project_scope(options={})
-    @query.results_scope(options)
+    @query.results_scope(options).tap do |result|
+      binding.b
+    end
   end

   def retrieve_project_query

Open /projects with "Last activity" column.

Then, @last_activity_date instance variable is exists following:

[334, 343] in ~/src/github.com/agileware-jp/redmine-dev-mirror/app/controllers/projects_controller.rb
   334|   private
   335|
   336|   # Returns the ProjectEntry scope for index
   337|   def project_scope(options={})
   338|     @query.results_scope(options).tap do |result|
=> 339|       binding.b
   340|     end
   341|   end
   342|
   343|   def retrieve_project_query
=>#0    block {|result=[#<Project:0x00007fe246c212c8 id: 1, name...|} in project_scope at ~/src/github.com/agileware-jp/redmine-dev-mirror/app/controllers/projects_controller.rb:339
  #1    Kernel#tap at <internal:kernel>:90
  # and 70 frames (use `bt' command for all frames)
(ruby) result.to_a.first.instance_variable_get(:@last_activity_date)
Fri, 01 Nov 2024 17:10:02.900305000 UTC +00:00
(ruby) result.to_a.first.instance_variable_get(:@last_activity_date).class
ActiveSupport::TimeWithZone
Actions #2

Updated by Nishida Yuya about 2 months ago

Nishida Yuya wrote:

r22811 changed return type of ProjectQuery#results_scope : Project::ActiveRecord_Relation => Array of Project instance

First time, I saw this return type change at r23172 (too late sorry...) and found r22811. Currently trunk (r23178) has same issue.

Actions #3

Updated by Mizuki ISHIKAWA about 2 months ago

I confirmed that the method works without issues after applying the patch.
For the plugin, there might be problems if the class of the returned instance changes, so I would like this patch to be incorporated.

I wrote a simple test and attached it.

Actions #4

Updated by Marius BĂLTEANU about 2 months ago

  • Related to Feature #23954: Shows the date of the last activity on Projects administration added
Actions #5

Updated by Marius BĂLTEANU about 2 months ago

  • Status changed from New to Closed
  • Assignee set to Marius BĂLTEANU

Committed the patches as part of #23954, thank you for finding and fixing this issue.

Actions #6

Updated by Nishida Yuya about 2 months ago

Mizuki ISHIKAWA Awesome!

Marius BĂLTEANU Thank you for your response!

Actions

Also available in: Atom PDF