Closed LonelyVikingMichael closed 1 year ago
Does this do what you want?
https://docs.litestar.dev/2/usage/dto/1-dto-factory.html#marking-fields
Not quite - I'll provide context.
During registration is_verified
is silently ignored, else the user could just skip verification by setting a bool.
However, internally we have a user creation method with a process_unsafe_fields
flag that takes is_verified
into account. The use case being "I am a privileged superuser who can create trusted accounts" - in which case skipping verification is sensible. Edit: This of course requires the field to be present during model instantiation.
I am aware that this can be solved by yet another DTO, making the distinction between UserRegister
and UserCreate
, it just seems arbitrary to users.
A self contained, minimal example that demonstrates your issue would be helpful.
I'd like to be able to mark individual DTO fields as optional
"optional" as in field type is to be made a union with None
, or not required to be submitted in the client payload?
What if a user isn't privileged, but in the api docs the is_verified
parameter is documented as an optional parameter, isn't this leaking abstraction to them?
As for the idea of granular setting of partial
, I think it makes sense. What about making DTOConfig.partial
accept either a bool, or set[str]
where the latter would be a set of field names to be made partial fields?
Summary
I'd like to be able to mark individual DTO fields as optional while other remain required. This is helpful where more nuance is required than
DTOConfig.partial
can provide.An
optional
keyword argument onDTOConfig
seems like the right approach.Basic Example
Drawbacks and Impact
I'm not sure how much benefit there would be to the community at large - this would be particularly helpful to
litestar-users
Unresolved questions
No response
Funding