Fork me on GitHub
#malli
<
2024-07-10
>
lyall08:07:53

is it a bad idea to try to do "check that no user with this email already exists" type of validation with malli? If not, I'd appreciate any pointers on how to pass my datasource to the validation fn. Seems like the validators take options but I haven't been able to figure out exactly what those options can be used for just yet

Stig Brautaset10:07:08

Similar questions have come up in this channel a few times. I think it's not a good idea. I would recommend restricting Malli to verify that the data is of the right "shape", not that you haven't seen that email before. (Nor that it's valid, for that matter, since only really attempting to send a validation email can do that.) That said, if you have an entity with multiple email addresses in it, you can certainly check that all those are distinct from eachother with Malli.

lyall10:07:06

seems reasonable but what's your rationale behind thinking it's a bad idea?

Stig Brautaset10:07:21

Performance cost is one reason, and difficulty of testing. https://clojurians.slack.com/archives/CLDK6MFMK/p1706115115762729?thread_ts=1706111434.068599&amp;cid=CLDK6MFMK There's also another thread here that you might find interesting: https://clojurians.slack.com/archives/CLDK6MFMK/p1691330835332889

🙏 1
didibus03:07:19

Doing side effects in the validation predicate sound like folly. I wouldn't do anything that needs that in it.

lyall05:07:56

I wouldn't say that doing a read operation from the db counts as a side effect, but I agree that this type of validation may be best done outside of malli

dominicm12:07:39

It might be neat to opt into it based on context.