# Testing django.tasks and understanding json Encoding

**URL:** <https://forum.djangoproject.com/t/testing-django-tasks-and-understanding-json-encoding/43876>\
**Category:** Using Django\
**Created:** [January 9, 2026, 8:30am UTC](https://forum.djangoproject.com/t/testing-django-tasks-and-understanding-json-encoding/43876 "2026-01-09T08:30:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kfdm](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kfdm/32/31172_2.png) [@kfdm](https://forum.djangoproject.com/u/kfdm)\
**Post date:** [January 9, 2026, 8:30am UTC](https://forum.djangoproject.com/t/testing-django-tasks-and-understanding-json-encoding/43876/1 "2026-01-09T08:30:00Z")

</div>

I have been recently studying the new django.tasks framework and testing a migration in my own project. At a high level, it is generally working great! and is letting me simplify some code in my projects. There are however some gotcha around certain types that are not technically bugs in django.tasks, but I wonder if they could be handled slightly nicer

For reference we need to know a few areas

normalize\_json ( [django/django/utils/json.py at 6.0 · django/django · GitHub](https://github.com/django/django/blob/6.0/django/utils/json.py#L4-L19) ) is called from various places in preparation for saving a Task to be executed

Django provides a built in DjangoJSONEncoder ( [django/django/core/serializers/json.py at 6.0 · django/django · GitHub](https://github.com/django/django/blob/6.0/django/core/serializers/json.py#L84-L113) ) though for many areas like JSONField it actually defaults to the default Python json.Encoder

A fairly common pattern for tasks, is to do extra processing on a model after creation, so we might have something like this

```python`  
`@receiver(post_save, sender='myapp.MyModel')`  
`def post_save_tasks(instance, **kwargs):`  
` my_task.enqueue(instance.pk)`  
`￼￼````

If our instance uses any of the integer keys, we’re fine, but if we happen to use UUIDField, we will get json encoding errors.

DjangoJSONEncoder handles a few more types like `uuid.UUID` and `Promise` that seem like would be useful for `normalize_json` could also handle.

---

<div class="post-metadata">

**Author:** ![kfdm](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kfdm/32/31172_2.png) [@kfdm](https://forum.djangoproject.com/u/kfdm)\
**Post date:** [January 9, 2026, 8:32am UTC](https://forum.djangoproject.com/t/testing-django-tasks-and-understanding-json-encoding/43876/2 "2026-01-09T08:32:22Z")

</div>

Originally started as a thread on Mastodon

[https://elk.zone/social.tsun.co/@kfdm/115863244456507659](https://social.tsun.co/@kfdm/115863244456507659)

With some other testing from my blog

> **[Migrating From Celery to Django Tasks](https://paultraylor.net/blog/2026/migrating-from-celery-to-django-tasks/)**
>
> Migrating from Celery to Django’s Task Framework is relaltively straight forward. There are only a few configuration changes needed, and a few simple substitutions. For more complicated tasks, consulting the tasks framework documentation is...

---

<div class="post-metadata">

**Author:** ![jacobtylerwalls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jacobtylerwalls/32/30603_2.png) [@jacobtylerwalls](https://forum.djangoproject.com/u/jacobtylerwalls)\
**Post date:** [January 9, 2026, 4:21pm UTC](https://forum.djangoproject.com/t/testing-django-tasks-and-understanding-json-encoding/43876/3 "2026-01-09T16:21:31Z")

</div>

Good question. This was [discussed](https://github.com/django/django/pull/18627#discussion_r2301760820) extensively before merge, and the consensus was we could consider a new feature adding a `TASK_SERIALIZER` setting for swappable serializers.

What we need now is a ticket at django/new-features showing the use case and musing on the interface. Are you up for that? 🎁

---

<div class="post-metadata">

**Author:** ![jacobtylerwalls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jacobtylerwalls/32/30603_2.png) [@jacobtylerwalls](https://forum.djangoproject.com/u/jacobtylerwalls)\
**Post date:** [January 9, 2026, 4:26pm UTC](https://forum.djangoproject.com/t/testing-django-tasks-and-understanding-json-encoding/43876/4 "2026-01-09T16:26:11Z")

</div>

Jake replied [here](https://github.com/django/django/pull/18627#discussion_r2309576633) with some ideas for where to take this.
