diff --git a/django_dramatiq/middleware.py b/django_dramatiq/middleware.py index 833cc7f..5e261b1 100644 --- a/django_dramatiq/middleware.py +++ b/django_dramatiq/middleware.py @@ -1,4 +1,5 @@ import logging +import traceback from django import db from dramatiq.middleware import Middleware @@ -46,6 +47,12 @@ def after_process_message(self, broker, message, *, result=None, exception=None, if exception is not None: status = Task.STATUS_FAILED + message.options['traceback'] = ''.join( + traceback.format_exception( + exception, + limit=30, + ) + ) elif status is None: status = Task.STATUS_DONE diff --git a/tests/test_admin_middleware.py b/tests/test_admin_middleware.py index 048b3c2..15100a4 100644 --- a/tests/test_admin_middleware.py +++ b/tests/test_admin_middleware.py @@ -52,6 +52,7 @@ def do_work(): task = Task.tasks.get() assert task assert task.status == Task.STATUS_FAILED + assert "RuntimeError" in task.message.options["traceback"] def test_admin_middleware_keeps_track_of_skipped_tasks(transactional_db, broker, worker):