-
Notifications
You must be signed in to change notification settings - Fork 8
DTO refactor, fix reference cycles #147
base: main
Are you sure you want to change the base?
Conversation
Thanks @gazorby I'll review asap! |
Sorry for the second burst, didn't see that you closed the other PR and I already did some work on it ;) |
Just letting you know that I probably won't get too deep into this until early next week as I have a bit on this weekend, but from a quick skim it looks nice and some very interesting ideas! |
for more information, see https://pre-commit.ci
- Decouple pydantic DTO implementation - Add support for default callable that accept SQLAlchemy context - Add support for static mehtod default callable - Cache generated dto so they can be reused as needed - Fix generation when relationships use string typed annotation - Bring back some unit tests
Hey @gazorby - DTOs are getting a big rework in starlite 2.0, so I've been sitting on my heals with this library until the beta is out there so there is some certainty with how it looks. We could keep the 0-version of the lib compatible with starlite 1.x and make the 1.x version of the lib starlite 2.x perhaps? |
No problem with that, Just want to keep this updated with my latest downstream changes as I need them, so we can choose what we want to keep or ditch. DTO changes for V2 are tracked in litestar-org/litestar/pull/1295 right? |
Also, do you plan to cover DTO ssaq features in Starlite V2 so we don't need this alternate implementation anymore? |
Hi @peterschutt!
My iteration based on #139 to fix reference cycles leads to another dto refactor.
Improvements
DTOFactory
base class that exposes common functionalities used to inspect SQLAlchemy models and may ease the implementation of other validation libraries under something like a dto protocol/interface that would be used by starlite-saqlalchemy. It also encapsulates some global state needed to resolve cycles.update_forward_refs()
on pydantic modelNone
if given as default (which is the case for scalar relationships).registry.mappers
(instead of relying solely onvars(module)
). It creates a hard dependency betweensaqlalchemy.db.orm
andsaqlalchemy.dto.from_mapped
but makes inference more reliable in non-trivial scenarios.