Action-specific parameter sanitization
Is there a way to sanitize a random map of params that is used for a specific action?
Here's my exact use case:
- I have a map coming from query string params
- That map may contain extra or invalid keys
- I want to filter out any keys that aren't a valid param/argument for that action
Right now if I don't sanitize the map and pass it along to an action, it fails with a
NoSuchInput
error:
I see though that Ash obviously knows about the expected parameters (with the arguments
keys on the query, and the inputs
key on the NoSuchInputError
).
I have found Ash.Filter.parse_filter/2
but it only sanitizes based on public attributes of a resource, not specific to an action.13 Replies
I know I could do that sanitization manually (which is what I do at the moment actually), but I feel like this is something Ash would offer straight out of the box
Solution
When calling the action you can do
skip_unknown_inputs: :*
Or when building the query
trying that out rn
yes, that seems to work! 😄
This is the fastest I've got support for anything ever, thanks @Zach Daniel !
Now, that option does not seem to be available when using Code Interface functions though.
If I try like
Accounting.search_accounts(%{invalid: :param}, skip_unknown_inputs: :*)
, it fails with the same NoSuchInputError
. Same thing if I try to get a query for that action instead: Accounting.query_to_search_accounts(...)
But that's not so bad, I'll convert those calls to Ash.Query.for_read
and it'll be okaynah you have to define it on the action iirc
what do you mean @kernel ?
oh! I'll try that as well
that's the only place I've ever seen it 🤷🏿♂️
it works! I like that even more
thanks 💜
it says it takes a list of params also, but I've never been able to get the list working, only
:*
/ [:*]
it would be impractical to exhaustively list all possible invalid inputs though 😆
yup