schrockwell / bodyguard

Simple authorization conventions for Phoenix apps

Home Page:https://hexdocs.pm/bodyguard/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overriding schema in `scope/4` appears to be broken?

coladarci opened this issue · comments

I'm passing in a query where the "schema can't be determined". I noticed I should be able to pass in schema: MySchema and be all set. It doesn't work, and when I look at the source code, it seems like it couldn't..

    {schema, params} =
      get_option("Bodyguard.scope/4", params, opts, :schema, resolve_schema(query))

When that line is run, it'll immediately run the last arg to get the default value and that bombs out because of this:

  # Unable to determine
  defp resolve_schema(unknown) do
    raise ArgumentError, "Cannot automatically determine the schema of
      #{inspect(unknown)} - specify the :schema option"
  end

I think what you need to do is pass in a fn that can be executed if the default is needed versus calculating the default ahead of time.

Are there tests for this and I am missing something?
Thanks!

Fixed in v2.4.1