I’ve recently upgraded from Ash 3.4.43 to 3.5.9 and I experienced some unexpected failures in my test suite. I get this error when trying to perform a simple relationship load:
** (Ash.Error.Unknown)
Bread Crumbs:
> Exception raised in: Tonic.Records.Prescription.read
> Exception raised in: Tonic.Pharmacy.RxGroup.read
Unknown Error
* ** (BadMapError) expected a map, got: nil
(stdlib 6.1.2) :maps.merge(nil, %{})
(ash 3.5.9) lib/ash/query/query.ex:3423: anonymous fn/2 in Ash.Query.data_layer_query/2
(elixir 1.17.3) lib/map.ex:916: Map.update!/3
(ash 3.5.9) lib/ash/query/query.ex:3420: Ash.Query.data_layer_query/2
(ash_sql 0.2.39) lib/query.ex:49: AshSql.Query.set_context/4
(ash 3.5.9) lib/ash/query/query.ex:3417: Ash.Query.data_layer_query/2
(ash 3.5.9) lib/ash/actions/read/read.ex:627: anonymous fn/8 in Ash.Actions.Read.do_read/5
(ash 3.5.9) lib/ash/actions/read/read.ex:1058: Ash.Actions.Read.maybe_in_transaction/3
(ash 3.5.9) lib/ash/actions/read/read.ex:326: Ash.Actions.Read.do_run/3
(ash 3.5.9) lib/ash/actions/read/read.ex:89: anonymous fn/3 in Ash.Actions.Read.run/3
(ash 3.5.9) lib/ash/actions/read/read.ex:88: Ash.Actions.Read.run/3
(ash 3.5.9) lib/ash/actions/read/relationships.ex:585: anonymous fn/3 in Ash.Actions.Read.Relationships.do_fetch_related_records/5
(ash 3.5.9) lib/ash/actions/read/relationships.ex:81: Ash.Actions.Read.Relationships.fetch_related_records/5
(ash 3.5.9) lib/ash/actions/read/relationships.ex:26: Ash.Actions.Read.Relationships.load/4
(ash 3.5.9) lib/ash/actions/read/read.ex:355: Ash.Actions.Read.do_run/3
(ash 3.5.9) lib/ash/actions/read/read.ex:89: anonymous fn/3 in Ash.Actions.Read.run/3
(ash 3.5.9) lib/ash/actions/read/read.ex:88: Ash.Actions.Read.run/3
(ash 3.5.9) lib/ash.ex:1914: Ash.load/3
(ash 3.5.9) lib/ash.ex:1868: Ash.load/3
(ash 3.5.9) lib/ash.ex:1809: Ash.load!/3e
It seems the data_layer
context is completely missing.
[(ash 3.5.9) lib/ash/query/query.ex:3413: Ash.Query.data_layer_query/2]
context #=> %{
private: %{tenant: "d3967913-d611-484d-b46e-0ab4703edb78"},
action: nil,
data_layer: nil
}
Not sure what I’m doing wrong here. Everything worked perfectly in the previous version of ash. Any help would be appreciated.
Have you updated the other Ash packages as well?
I started out updating all deps, but my whole test suite blew up. I then rolled back and updated just ash. Updating fixes this issue 
But now I remembered the error I was encountering to begin with. It’s with AshPaperTrail.
Unknown Error
* ** (Protocol.UndefinedError) protocol Enumerable not implemented for ~D[2086-10-06] of type Date (a struct). This protocol is implemented for the following type(s): DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Floki.HTMLTree, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Iter, Jason.OrderedObject, List, Map, MapSet, Phoenix.LiveView.LiveStream, Postgrex.Stream, Range, Req.Response.Async, Rewrite, Stream, StreamData, Table.Mapper, Table.Zipper, Timex.Interval
(elixir 1.17.3) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir 1.17.3) lib/enum.ex:166: Enumerable.reduce/3
(elixir 1.17.3) lib/enum.ex:4423: Enum.map/2
(ash_paper_trail 0.3.1) lib/resource/changes/create_new_version.ex:243: AshPaperTrail.Resource.Changes.CreateNewVersion.extract_casted_params_values/2
(ash_paper_trail 0.3.1) lib/resource/changes/create_new_version.ex:184: anonymous fn/3 in AshPaperTrail.Resource.Changes.CreateNewVersion.build_notifications/3
(elixir 1.17.3) lib/enum.ex:2531: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash_paper_trail 0.3.1) lib/resource/changes/create_new_version.ex:157: AshPaperTrail.Resource.Changes.CreateNewVersion.build_notifications/3
(ash_paper_trail 0.3.1) lib/resource/changes/create_new_version.ex:63: anonymous fn/2 in AshPaperTrail.Resource.Changes.CreateNewVersion.create_new_version/1
(ash 3.5.9) lib/ash/changeset/changeset.ex:4266: anonymous fn/2 in Ash.Changeset.run_after_actions/3
(elixir 1.17.3) lib/enum.ex:4858: Enumerable.List.reduce/3
(elixir 1.17.3) lib/enum.ex:2585: Enum.reduce_while/3
(ash 3.5.9) lib/ash/changeset/changeset.ex:3744: anonymous fn/3 in Ash.Changeset.with_hooks/3
(ecto_sql 3.12.1) lib/ecto/adapters/sql.ex:1400: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
(db_connection 2.7.0) lib/db_connection.ex:1756: DBConnection.run_transaction/4
(ash 3.5.9) lib/ash/changeset/changeset.ex:3742: anonymous fn/3 in Ash.Changeset.with_hooks/3
(ash 3.5.9) lib/ash/changeset/changeset.ex:3886: anonymous fn/2 in Ash.Changeset.transaction_hooks/2
(ash 3.5.9) lib/ash/changeset/changeset.ex:3729: Ash.Changeset.with_hooks/3
(ash 3.5.9) lib/ash/actions/create/create.ex:261: Ash.Actions.Create.commit/3
(ash 3.5.9) lib/ash/actions/create/create.ex:132: Ash.Actions.Create.do_run/4
(ash 3.5.9) lib/ash/actions/create/create.ex:50: Ash.Actions.Create.run/4
I’ll keep digging into it and see what I can find. That’s what I get for context switching. If I can’t make any progress I’ll post in another topic. Next time I’ll try turning it off and then on again
before reaching out.