Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

Commit db60986

Browse files
authored
FIX: skip notifications when topic is not found (#634)
Fixes a bug where the topic may already be deleted before the notification job runs, causing the job to fail.
1 parent 77dc3ab commit db60986

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/discourse_assign/create_notification.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def initialize(assignment:, user:, mark_as_read:)
6868
end
6969

7070
def call
71+
return if topic.nil?
7172
Assigner.publish_topic_tracking_state(topic, user.id)
7273
unless mark_as_read?
7374
PostAlerter.new(post).create_notification_alert(

spec/lib/discourse_assign/create_notification_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@
2424
create_notification
2525
end
2626

27+
context "when topic is not found" do
28+
before { assignment.topic = nil }
29+
30+
it "does not publish topic tracking state" do
31+
Assigner.expects(:publish_topic_tracking_state).never
32+
create_notification
33+
end
34+
35+
it "does not create a notification alert" do
36+
alerter.expects(:create_notification_alert).never
37+
create_notification
38+
end
39+
end
40+
2741
context "when `mark_as_read` is false" do
2842
let(:excerpt) do
2943
I18n.t(

0 commit comments

Comments
 (0)