Skip to content

id as UUID is causing errors #341

@wdifruscio

Description

@wdifruscio

I do not use integer pks - its a very old project with uuid4s

I get a to_dict() error when defaulting to the id.

custom_objectID = 'field' would work, if I could just return str(instance.id) but I can't find a way to do this. Maybe I missed something.

For now, I am either going to have to create a custom_id property on each model..

My Error

  File "/usr/local/lib/python3.12/site-packages/algoliasearch/http/serializer.py", line 64, in body_serializer
    obj_dict = obj.to_dict()
               ^^^^^^^^^^^
AttributeError: 'UUID' object has no attribute 'to_dict'

Model

import uuid

class UUIDModel(models.Model):
    id = models.UUIDField(primary_key=True, editable=False, default=uuid.uuid4)

    class Meta:
        abstract = True

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions