oban-bg/oban

Enqueueing a job with a non-serializable value (changeset) causes error

Closed this issue · 1 comments

Environment

  • Oban Version: 2.17.6
  • Sqlite version: 3.44.2
  • Elixir & Erlang/OTP Versions (elixir --version): Elixir 1.16.1 (compiled with Erlang/OTP 25)

Current Behavior

Enqueueing a job that contains an unserializable value, such as an Ecto.Changeset causes the following error:

[error] GenServer #PID<0.831.0> terminating
** (FunctionClauseError) no function clause matching in Ecto.Type.process_dumpers/3
    (ecto 3.11.1) lib/ecto/type.ex:945: Ecto.Type.process_dumpers([], {:error, %Protocol.UndefinedError{protocol: Jason.Encoder, value: #Ecto.Changeset<action: nil, changes: %{description: "asdfasdf"}, errors: [], data: #Sorgenfri.Assets.Asset<>, valid?: true>, description: "Jason.Encoder protocol must always be explicitly implemented.\n\nIf you own the struct, you can derive the implementation specifying which fields should be encoded to JSON:\n\n    @derive {Jason.Encoder, only: [....]}\n    defstruct ...\n\nIt is also possible to encode all fields, although this should be used carefully to avoid accidentally leaking private information when new fields are added:\n\n    @derive Jason.Encoder\n    defstruct ...\n\nFinally, if you don't own the struct you want to encode to JSON, you may use Protocol.derive/3 placed outside of any module:\n\n    Protocol.derive(Jason.Encoder, NameOfTheStruct, only: [...])\n    Protocol.derive(Jason.Encoder, NameOfTheStruct)\n"}}, Ecto.Adapters.SQLite3)
    (ecto 3.11.1) lib/ecto/repo/schema.ex:1044: Ecto.Repo.Schema.dump_field!/6
    (ecto 3.11.1) lib/ecto/repo/schema.ex:1058: anonymous fn/6 in Ecto.Repo.Schema.dump_fields!/5

Here's a simplified version of the code I used:

changeset =
  Foos.change_foo(%Foo{}, foo_params)

%{changeset: changeset}
  |> MyApp.Workers.FooWorker.new()
  |> Oban.insert()

Expected Behavior

I realize that this may be expected behavior from Oban. After all, how are you going to serialize arbitrary structs into json for the database. However, I didn't really see this restriction documented anywhere, nor could I find any other error reports documenting the error, so I thought I'd post this here for others like me who run into similar problems.

Feel free to close the issue without doing anything 😄

@Munksgaard Thank you for opening an issue, it's sure to help others in the future. I've also added a note to the primary docs/readme to clarify the difference.

🌟 For your reference, and any others who stumble on this, Oban Pro's structured jobs enables encoding/decoding of arbitrary values in job args.