Skip to content

Commit 62b2e9b

Browse files
authored
Merge pull request #763 from LincolnPuzey/fix_raising_exception
Fix edge case where `None` would be raised as exception in `StubBroker.join()`
2 parents 594b112 + d0ede16 commit 62b2e9b

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

dramatiq/brokers/stub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def join(self, queue_name: str, *, timeout: Optional[int] = None, fail_fast: boo
173173
else:
174174
if fail_fast:
175175
for message in self.dead_letters_by_queue[queue_name]:
176-
raise message._exception from None
176+
raise (message._exception or Exception("Message failed with unknown error")) from None
177177

178178
return
179179

dramatiq/worker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,14 @@ def handle_message(self, message: MessageProxy) -> None:
364364
actor = self.broker.get_actor(message.actor_name)
365365
self.logger.debug("Pushing message %r onto work queue.", message.message_id)
366366
self.work_queue.put((actor.priority, message))
367-
except ActorNotFound:
367+
except ActorNotFound as e:
368368
self.logger.error(
369369
"Received message for undefined actor %r. Moving it to the DLQ.",
370370
message.actor_name,
371371
exc_info=True,
372372
)
373373
message.fail()
374+
message.stuff_exception(e)
374375
self.post_process_message(message)
375376

376377
def post_process_message(self, message: MessageProxy) -> None:

tests/test_actors.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import dramatiq
1111
from dramatiq import Message, Middleware
12-
from dramatiq.errors import RateLimitExceeded
12+
from dramatiq.errors import ActorNotFound, RateLimitExceeded
1313
from dramatiq.middleware import CurrentMessage, SkipMessage
1414

1515
from .common import skip_on_pypy, worker
@@ -316,7 +316,8 @@ def test_messages_belonging_to_missing_actors_are_rejected(stub_broker, stub_wor
316316
stub_broker.enqueue(message)
317317

318318
# Then join on the queue
319-
stub_broker.join("some-queue")
319+
with pytest.raises(ActorNotFound, match=r"^some-actor$"):
320+
stub_broker.join("some-queue", fail_fast=True)
320321
stub_worker.join()
321322

322323
# I expect the message to end up on the dead letter queue

0 commit comments

Comments
 (0)