News for hackers. Stuff that matters.
Re:Pydantic-resolve, a hierarchical solution for data fetchi... by thornewolf on Monday February 26, 2024 @02:07PM (#39515535)
say you have a model with two attributes profile_image_url: str and profile_image: bytes

it's expensive to fetch profile_image since it will involve a http call to profile_image_url. right now, i would resolve this by using the @property decorator

this library offers an alternative method for populating profile_image by explicitly giving the user a hook for when they want to resolve this dependency. they might want to do it before access time, they might want to batch requests to this external profile_image service to reduce roundtrip latency

this pattern has potential to become more powerful if we only have user_id in context initially. we might want to fetch the product_image_url from the database then fetch the actual product_image after. this dependency graph might be simplified/optimized using this tool

the repo provides its own concrete example of this form with batch_person_age_loader

Re:Pydantic-resolve, a hierarchical solution for data fetchi... by navbaker on Monday February 26, 2024 @02:33PM (#39515837)
Thanks!
Re:Pydantic-resolve, a hierarchical solution for data fetchi... by Gimpei on Monday February 26, 2024 @04:52PM (#39517166)
I too was confused. If the authors are reading this, the readme could do with a little bit more of an intro.
Re:Pydantic-resolve, a hierarchical solution for data fetchi... by tangkikodo on Monday February 26, 2024 @05:33PM (#39517560)
my fault lol.

here is a step by step tutorial, building various kinds of views data you need, and keep service layer simple and clear at the same time.

https://github.com/allmonday/composition-oriented-developmen...

code is ready, documents of english version is still wip.

Re:Pydantic-resolve, a hierarchical solution for data fetchi... by codetrotter on Monday February 26, 2024 @04:55PM (#39517210)
That sounds pretty useful.

Anyone know of a library to do the same in Rust?