You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the message contains the datetime.datetime fields it isn't able to load message in django admin task detail view. Results into TypeError.
I had to override the TaskAdmin.message_details to do something like this json.dumps(instance.message._asdict(), indent=4, cls=DjangoJSONEncoder) # Using DjangoJSONEncoder here
and unregister and register with this CustomTaskAdmin.
Any other ways to mitigate it ?
The text was updated successfully, but these errors were encountered:
Actually Issue arises, when django_dramatiq.admin.TaskAdmin tries to produce message_details
which is then displayed in task details in django admin details view. It actually is a display error where it is not able to convert instance.message if this message has a datetime.datetime type of field.
So when somebody accesses a Task detail in django admin url like /system/admin/django_dramatiq/task/8rthr4502-c715-4a96-b41f-b77c75hggc12e/change/ , raises TypeError: Object of type datetime is not JSON serializable.
So to mitigate it I had to dome something like this.
admin.site.unregister(Task)
@admin.register(Task)
class CustomTaskAdmin(TaskAdmin):
def message_details(self, instance):
"""
Overriding TaskAdmin from django_dramatiq to avoid Serialization Errors for datetime objects.
In future if fixed by library, this can be removed.
"""
message_details = json.dumps(instance.message._asdict(), indent=4, cls=DjangoJSONEncoder) # noqa: SLF001
return mark_safe("<pre>%s</pre>" % message_details)
So here I am providing DjangoJSONEncoder which fixes it.
Not sure if it's best option but it wokred for me
If the message contains the datetime.datetime fields it isn't able to load message in django admin task detail view. Results into TypeError.
I had to override the TaskAdmin.message_details to do something like this
json.dumps(instance.message._asdict(), indent=4, cls=DjangoJSONEncoder)
# Using DjangoJSONEncoder hereand unregister and register with this CustomTaskAdmin.
Any other ways to mitigate it ?
The text was updated successfully, but these errors were encountered: