Open ryanolf-tb opened 6 months ago
Not dismissing the behavior, but just pointing this out zip: Mapped[str] = mapped_column(info=dto_field('private'))
can be used to ignore it via the plugin
dto_field
is litestar.dto.dto_field
I think in the typical CRUD use case one would use dto_field
. In my example, I can just use return_dto
instead of dto
. This may not have been brought up before because it is not encountered much in practice, and it's easy to work around if one understands the behavior.
Description
Based on the docs, I expect a DTO given to a handler via the
dto
parameter to apply to the return value when noreturn_dto
is specified. However, when theSQLALchemyPlugin
is used this is not the case.More generally, it looks like the
return_dto
resolution order in theBaseRouteHandler
puts generated DTOs from serialization plugins ahead of DTOs from explicitdto
parameters on the handler. For me this is not the expected behavior based on the documentation, though I can see that one may want to opt-in to thereturn_dto
provided by the plugin while still providing a data DTO, which perhaps is the reason for the current behavior.It may be that the docs just need an update to clarify? An alternative might be to specify a particular value that can be passed to the
return_dto
parameter to maintain the current behavior, but to otherwise resolve todto
if it's given.URL to code causing the issue
No response
MCVE
Steps to reproduce
Screenshots
Logs
Litestar Version
2.8.2
Platform