-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Feature/obbject to dict #5557
Feature/obbject to dict #5557
Conversation
|
||
return item | ||
|
||
return nested_model_to_dict(self.results) |
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.
Does it cover your use case if we just implement in one line?
def to_dict(self) -> Dict
"Docstring"
return self.model_dump()["results"]
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.
🤦🏻♂️Lmao, this what happens when doing a @DidierRLopes task at 1am.
Yeah this for sure the best way to go!!
I think this was a choice because as a dict like this, it is actually more of a list and the "fields" are not keyable, you need to convert from a List, whereas like a Dict of Lists, you can key and entire field, like A dict("records") gives you essentially the same thing as |
We've had this discussion before in the past, and this was the final decision. List of dicts it's what is used in practice by everyone. Dicts of list is unnatural, so it's fine for us to support it but as And we don't want to leave this as user criteria for the same method since we want to have as much deterministic as possible . |
The only reason I suggest it was a choice somewhere, instead of a regression, is that it has been added to the documentation under |
Gotcha. Sorry @deeleeramone. @jmaslek , I'm not getting that output with Can we add an argument |
Yeah the results output you see is python/pydantic stuff, but on the fastapi end it's converted to what I showed. Yup we can either add an orient or just skip straight to a to_records/to_json method. Dealers choice. |
So I suggest doing both:
@andrewkenreich @jose-donato any comment on this? |
Closing in favor of #5588 |
@jmaslek this should fix the issue with the
to_dict()
which seemed that it was hitting a regression?Before
After