-
Notifications
You must be signed in to change notification settings - Fork 330
Open
Description
Problem
Viewing the job page leads to a server error if the job.meta
contains objects that are not serializable by the default JSONEncoder
.
Currently, rq-dashboard serializes job metadata like this (in web.py
):
json.dumps(job.get_meta())
This uses the default JSON encoder. In some cases, job metadata may contain types that aren’t JSON-serializable by default (e.g., datetime.datetime
, datetime.timedelta
, and corresponding Pandas classes). This causes serialization errors when viewing job details in the dashboard.
Proposal
It would be helpful if rq-dashboard allowed users to configure or pass a custom json.JSONEncoder
(or a callable) for this serialization step. For example:
- Add a configuration option (e.g.,
RQ_DASHBOARD_JSON_ENCODER
) that points to aJSONEncoder
subclass or function. - Or, allow passing an encoder when initializing the dashboard app.
For example:
from datetime import datetime
class CustomEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime):
return obj.isoformat()
return super().default(obj)
# somewhere in config
RQ_DASHBOARD_JSON_ENCODER = CustomEncoder
And the desired change in web.py
:
json.dumps(job.get_meta(), cls=current_app.config.get("RQ_DASHBOARD_JSON_ENCODER", json.JSONEncoder))
Would you be open to a PR adding this configurability?
Metadata
Metadata
Assignees
Labels
No labels