-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON serializer cannot serialize UUID values #973
Comments
We don't have any way to know which fields will be a uuids so the only way to do this would be to go though every field of every document and check it. That is going to be a decent performance hit for something that isn't going to be very common. Since you will know which fields will be a uuid you could convert them yourself before sending it. my_docs = [{"uuid_field": UUID4(), "title": "Some Title"}]
for doc in my_docs:
doc["uuid_field"] = str(doc["uuid_field"]) |
You wouldn't have to go through each field if you were using orjson, but I completely understand you don't want that extra dependency. Maybe I should add this as a suggestion issue, but have custom serializers ever been considered? Something like:
|
This isn't something we have discussed, but I wouldn't rule it out as an option. While not everyone will have uuids it's not so niche that you are going to be the only person doing it. |
Thanks, it works great! I use |
Description
When adding a document containing a UUID value, the library's JSON serializer fails.
Expected behavior
That the internal JSON serializer converts UUID values to str values.
Current behavior
Environment (please complete the following information):
My current workaround uses orjson which can serialize UUID fields:
but it would be better if this workaround is unnecessary.
The text was updated successfully, but these errors were encountered: