Oban.Pro.Decorator fails to compile with opts \\ []

I’m trying to use a new Oban.Pro.Decorators, but it fails to compile when I use opts \\ [].
Is this a limitation or a bug?

defmodule MyApp.Business do
  use Oban.Pro.Decorator

  @job true
  def weekly_report(tps_id, opts \\ []) do
    {:ok, "report"}
  end
end
    error: def new_weekly_report/3 defaults conflicts with new_weekly_report/2
    │
  1 │ defmodule MyApp.Business do
    │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^

I’m using Oban.Pro 1.5.0-rc.3

That’s a limitation (for now) because of the compile time gymnastics required to generate all of the decorated clauses. Eventually we’ll handle defaults, but for now you need to pass the empty options list through at the call site.

1 Like

Bumping! Just came across this issue using Oban.Pro 1.6.0 :folded_hands:

Lost track of this one, sorry. The ambiguity of multiple arguments with defaults makes this difficult to implement, and even trickier to understand. That’s because the decorated function also has an optional clause.

Take the following example:

@job true
def foo(opts \\ []) do
  ...
end

If that worked, you’d have new_foo/0, new_foo/1, and new_foo/2 where new_foo/1 would ambiguously take either the optional args for foo, or options for new, with no way for the decorator (or you as a developer) to differentiate.

The best option may be to detect that the decorated function has optional args and provide a clearer error that explains the problem clearly :thinking: