-
Notifications
You must be signed in to change notification settings - Fork 4
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
TypeError thrown when serializing UUIDField #9
Comments
I've ran into this issue myself. I'd consider explicitly declaring a serialize on
|
Hmm, this seems to be a temp fix. It would be great if the UUID Fields could be rendered just like how JSONRenderer handles them. |
Yeah so it looks like the built in |
I think the closest thing to a fix at the renderer level would be something like follows. class UJSONRenderer:
translate_func = lambda v: v
def render(self, ...):
# ...
ret = ujson.dumps(self.translate_func(data), ...) Where you can write a function that translates your response into a ujson serializable object. There would be performance implications obviously that should be explored. |
I might implement this in an alpha release and see how it goes. |
Would love to see this– I'm using UUIDs for all of my PKs. Doesn't sound like |
@aaronn The last time I looked (haven't in a while) at ujson they were going to add support for custom encoders. So my thought was wait to see what that interface looks like. I'll have to look into what their timeline is now. Last I checked they basically said if |
Just checked the issue and they've removed it from the milestone. It doesn't look like something they have any plans to prioritize. |
Alright I'll put something out on this. I have had time for this I just haven't made time. |
For this to work you'll have to implement a recursive function that will traverse the various structures and types. I think the recursion will really matter around |
I actually think I have the typing wrong on |
Something like this. def translate(data: Any):
if isinstance(data, list):
return [translate(d) for d in data]
if isinstance(data, dict):
return {key: translate(value) for key, value in data.items()}
if isinstance(data, uuid.UUID):
return str(data)
return data could be wrong though 🤷 |
Issue rendering UUID field as foreign key
Photo
objects throw TypeError when using UJSONRendererOutput from shell
Models & Serializers
Photo
object?The text was updated successfully, but these errors were encountered: