Replies: 1 comment 1 reply
-
Can you elaborate? It seems like the right approach to me.
That's correct. The default library used to validate things in Litestar is The validation offered here is to assert that the data provided has the right shape and schema, not about enforcing semantics. When doing the latter, it definitely makes sense to collect multiple errors in one go, but when doing the former, things can get messy / undeterministic. This is what e.g. Pydantic does, and many of its quirks can be attributed to this.
I'd say it's explicit and coherent :)
Not sure about that either. Seems like something has changed in pyright, although it doesn't seem to be failing on our end when we test against pyright. Can you maybe open an issue for this? :) |
Beta Was this translation helpful? Give feedback.
-
Hi! I'm new to Litestar and am trying to build a simple old-school web app — that is, one that returns HTML, not JSON, from its endpoints.
I'm curious what patterns Litestar users have adopted for handling bog-standard form POSTs and returning HTML.
For my first attempt, I tried to use Litestar's built-in data validation. I think that ended up being the wrong idea:
Okay, so clearly not how to do things. :-) But, some notes:
example_form_post(...)
toexample_form_post_error(...)
feels verboseAnnotated[...]
just to say "hey, expect url encoded data" feels verbosepyright
complains about the type ofexception_handlers
if therequest
parameter ofexample_form_post_error()
is alitestar_htmx.HTMXRequest
rather than alitestar.Request
. It seems like this shouldn't happen since the underlyingExceptionHandler
type is defined asCallable[[Request, ExceptionT], Response]
... but it definitely does happen with the latest build of pyrightSo... that doesn't seem like the right approach to form handling in Litestar. No worries; I see that
request.form()
exists, but I'd still like to maybe reuse Litestar's validation features if it's possible. Maybe it's not; I'm not sure.How can I take advantage of some of Litestar's goodness here, while having more straightforward form handlers? Or should I just use
request.form()
, dump that into (say) apydantic
orcattrs
type (or roll my own validation) and go from there?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions