Skip to content

Commit

Permalink
Fix for Bogdanp#135 -- when using the PickleEncoder make sure the tas…
Browse files Browse the repository at this point in the history
…k view still works by showing a representation of the kwargs which is json serializable
  • Loading branch information
Huub Bouma committed Nov 13, 2022
1 parent 633024c commit b0b8d00
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion django_dramatiq/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from django.contrib import admin
from django.utils import timezone
from django.utils.safestring import mark_safe
from django_dramatiq.apps import DjangoDramatiqConfig
from dramatiq.encoder import JSONEncoder

from .models import Task

Expand Down Expand Up @@ -35,7 +37,16 @@ def eta(self, instance):
return datetime.fromtimestamp(timestamp, tz=tz)

def message_details(self, instance):
message_details = json.dumps(instance.message._asdict(), indent=4)
message_dict = instance.message._asdict()

# make sure we can still get a representation of the
# kwargs payload when a non json encoder is in use
kwargs_encoder = DjangoDramatiqConfig.select_encoder()
if not isinstance(kwargs_encoder, JSONEncoder):
for k,v in message_dict['kwargs'].items():
message_dict['kwargs'][k] = f"<{v}>"

message_details = json.dumps(message_dict, indent=4)
return mark_safe("<pre>%s</pre>" % message_details)

def traceback(self, instance):
Expand Down

0 comments on commit b0b8d00

Please sign in to comment.