I'm using django_celery_results
to save results of some celery tasks. Each task gets kwargs
as input which at the end gets saved in task_kwargs
field of TaskResult
.
Im having trouble loading those kwargs
later from the way they get saved in DB. For example this is one entry:
"{'config_file_path': '/path/to/configs/some_config.json'}"
Simple example of accessing the field value:
tkwargs = TaskResult.objects.get(id=1).task_kwargs
for which i get the above string.
What is a straightforward way to get task_kwargs
as a python dictionary instead of that string?
This is what I have:
args = json.loads(task.task_kwargs)
if isinstance(args, str):
args = args.replace("'", '"')
args = json.loads(args)
Not pretty, but it works.