🐛 Recurse into dataclass when encoding#4454
Conversation
don4of4
left a comment
There was a problem hiding this comment.
Looks good -- encountered this issue in our projects as well.
|
Shouldn’t the keyword arguments of |
Yep, updated it now. Sorry to have duplicated your existing PR! |
|
No problem, just hope it gets merged :) |
This makes the behaviour of include/exclude easier to see
|
@don4of4 Thanks for the review. Do you see any chances, that this PR will be merged in the near future? |
|
My PR #3607 got merged. I think you can close this one now! 🚀 |
|
Thanks for the effort @ConorStevenson! ☕ It seems this was solved by #3607, right? Given that, I'll close this one. But if you feel there's something else that needs to be done, feel free to create a new PR. Thanks! 😄 |
Context:
PR #3576 added support for dataclasses as response objects.
Problem:
json_encoderdoesn't recurse into dataclasses as it does for pydantic models, dictionaries, and other collections. Custom encoders aren't applied to attributes on dataclasses.Solution:
Recurse into dataclasses when encoding. Also change dataclass tests to use dataclasses rather than pydantic models.
Example: