ospaarmann/exdgraph

set_map doesn't work with DateTime in map

optikfluffel opened this issue · 1 comments

It seems set_map/2 doesn't work when there's a DateTime in the map. My best guess would be that the fact that DateTime is a map itself messes something up here.

Failing test for test/mutation_test.exs:

test "set_map/2 works with DateTime", %{conn: conn} do
  map_with_datetime_insert_mutation = %{
    name: "Alice",
    identifier: "alice_json",
    created_at: DateTime.utc_now()
  }

  {status, mutation_msg} = ExDgraph.set_map(conn, map_with_datetime_insert_mutation)
  assert status == :ok
  assert mutation_msg.context.aborted == false
end

Which results in:

  1) test set_map/2 works with DateTime (MutationTest)
     test/mutation_test.exs:121
     ** (Protocol.UndefinedError) protocol Enumerable not implemented for #DateTime<2019-05-10 21:37:46.845058Z>. This protocol is implemented for: DBConnection.Stream, DBConnection.PrepareStream, HashSet, Range, Map, Function, List, Stream, Date.Range, HashDict, GenEvent.Stream, MapSet, File.Stream, IO.Stream
     code: {status, mutation_msg} = ExDgraph.set_map(conn, map_with_datetime_insert_mutation)
     stacktrace:
       (elixir) /private/tmp/elixir-20190202-21222-1ilp2g0/elixir-1.8.1/lib/elixir/lib/enum.ex:1: Enumerable.impl_for!/1
       (elixir) /private/tmp/elixir-20190202-21222-1ilp2g0/elixir-1.8.1/lib/elixir/lib/enum.ex:141: Enumerable.reduce/3
       (elixir) lib/enum.ex:3015: Enum.reduce/3
       (ex_dgraph) lib/exdgraph/mutation.ex:129: anonymous fn/2 in ExDgraph.Mutation.insert_tmp_uids/1
       (stdlib) maps.erl:257: :maps.fold_1/3
       (ex_dgraph) lib/exdgraph/mutation.ex:28: ExDgraph.Mutation.set_map/2
       test/mutation_test.exs:128: (test)

@optikfluffel I am working on a larger release right now and will tackle this issue as part of it. Thank you for bringing it to my attention.

WIP here: https://github.com/ospaarmann/exdgraph/tree/update_to_db_connection_2