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
🐛 Recurse into dataclass when encoding #4454
🐛 Recurse into dataclass when encoding #4454
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_encoder
doesn'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: