Open 2jun0 opened 3 months ago
📝 Docs preview for commit 2d9af2f8e3fc04172120ef062e8c8378e0bca708 at: https://bfab4bb5.sqlmodel.pages.dev
📝 Docs preview for commit 548f0050b3df31e0206d9157b2715912ff7ca643 at: https://d4117a75.sqlmodel.pages.dev
📝 Docs preview for commit 1d7f73e03ab0440d81719b7ce0a1398296acc1ab at: https://b18eab40.sqlmodel.pages.dev
@tiangolo this is very useful. My workaround now is a ton of lazy loads
I'm not that good at English. So, if there's anything you don't understand, please feel free to reply.
Currently, accessing some fields asynchronously is hard. I often encounter the MissingGreenlet error while programming asynchronously, which happens because attempting IO without using await keyword when accessing lazy loading or expired fields. (others seem to have this problem too #868 #74)
While SQLAlchemy provides the AsyncAttr Mixin, I found it not suitable for sqlmodel because the completion wasn't good enough.
So, I propose an AwaitableField, making access to other fields awaitable like below:
Usage
Create a AsyncSQLModel and add an awaitable field
You can easliy create a AsyncSQLModel Using the same interface as a sqlmodel. and an AwaitableField yields an awaitable field for the field specified in the argument.
This allows fields which may be subject to lazy loading or deferred / unexpiry loading to be accessed like this:
Access a Relationship Field using an AwaitableField
Using an AwaitableField with Relationship fields can resolve the problem encountered during lazy loading