Ash FrameworkAF
Ash Framework7mo ago
18 replies
marcofiset

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:
Ash.Query.for_read(Account, :search, %{type: :asset, invalid: :key})
#Ash.Query<
  ...
  action: :search,
  arguments: %{type: :asset, search: ""}
  errors: [
    %Ash.Error.Invalid.NoSuchInput{
      input: :invalid,
      inputs: [:search, :type],
      ...
    }
  ]


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.
Solution
When calling the action you can do skip_unknown_inputs: :*
Was this page helpful?