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 ) 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 ) 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.