From 68121841b5f830851912a09265998f8ee86fd31c Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Tue, 10 Sep 2024 00:55:32 +0000 Subject: [PATCH] Fix NoMethodError in Issue#blocked? due to invalid issue_from_id in Issue#relations_from (#8539). Patch by Go MAEDA (user:maeda). git-svn-id: https://svn.redmine.org/redmine/trunk@23048 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 2 +- test/unit/issue_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 9b47ce7bd..3debf90ec 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1018,7 +1018,7 @@ class Issue < ApplicationRecord # Returns true if this issue is blocked by another issue that is still open def blocked? - !relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil? + relations_to.any? {|ir| ir.relation_type == 'blocks' && ir.issue_from&.closed? == false} end # Returns true if this issue can be closed and if not, returns false and populates the reason diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 7480fbc55..ca2531e58 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -2222,6 +2222,16 @@ class IssueTest < ActiveSupport::TestCase assert !blocking_issue.blocked? end + def test_blocked_should_not_raise_exception_when_blocking_issue_id_is_invalid + ir = IssueRelation.find_by(issue_from_id: 10, issue_to_id: 9, relation_type: 'blocks') + issue = Issue.find(9) + assert issue.blocked? + + ir.update_column :issue_from_id, 0 # invalid issue id + issue.reload + assert_nothing_raised {assert_not issue.blocked?} + end + def test_blocked_issues_dont_allow_closed_statuses blocked_issue = Issue.find(9) -- 2.39.5