[Python] UUID Is not JSON Serializable (dumpdata)

Discussão em 'Python' iniciado por Stack, Março 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'm having an issue with the command dumpdata. I'm using django-uuidfield as primary key for a few of my models, however; whenever I try to run dumpdata, I run into the error

    TypeError: UUID('...') is not JSON serializable.

    I found that inside of Django's DjangoJSONEncoder class that it doesn't check for the UUID object and will go to the default() of the parent class which throws the exception.

    When I added a check, it seemed to work properly without any errors or warnings.

    I'm not sure if that's a bug or I'm doing something wrong.

    Note:

    I didn't change any code inside django-uuidfield.

    Thanks.

    Edit:

    The dumpdata works for another model where the uuidfield is not set to auto. The one that doesn't work has the uudfield set to auto.

    Continue reading...

Compartilhe esta Página