circles-learning-labs / ecto_adapters_dynamodb

DynamoDB adapter for Elixir's Ecto Database layer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nil value for fields using the source field option

msmithstubbs opened this issue · comments

I've been testing the 2.0.0-alpha.1 version locally and believe I've confirmed a regression. A schema that uses a field with the source option returns nil for the field rather than restoring the field value. Here's an example test case:

defmodule Ecto.Adapters.DynamoDB.TestSchema.Moon do
  use Ecto.Schema
  @primary_key {:id, :binary_id, autogenerate: true}
  @foreign_key_type :binary_id

  schema "test_planet" do
    field :name, :string
    field :adjective, :string, source: :data1
  end
end

defmodule Ecto.Adapters.DynamoDB.SourceFieldTest do
  use ExUnit.Case
  import Ecto.Query

  setup_all do
    TestHelper.setup_all()

    on_exit(fn ->
      TestHelper.on_exit()
    end)
  end

  test "using a field with the source option" do
    alias Ecto.Adapters.DynamoDB.TestSchema.Moon

    changeset = Ecto.Changeset.change(%Moon{}, %{name: "Europa", adjective: "Europan"})
    {:ok, europa} = Ecto.Adapters.DynamoDB.TestRepo.insert(changeset)

    %Moon{adjective: adjective} = Ecto.Adapters.DynamoDB.TestRepo.get(Moon, europa.id)
    assert adjective == "Europan" 
  end
end

The assertion is expected to pass, but fails:

  1) test OK (Ecto.Adapters.DynamoDB.SourceFieldTest)
     test/source_field_test.exs:26
     Assertion with == failed
     code:  assert adjective == "Europan"
     left:  nil
     right: "Europan"
     stacktrace:
       test/source_field_test.exs:35: (test)

Any thoughts on what could be the cause?

Ah sorry - I realized that perhaps you're asking for a tip on where to start looking for the source of this problem yourself - probably the best place to start digging is execute/5 in the main module, lib/ecto_adapters_dynamodb.ex - check out the arguments that that function is receiving. I'd bet that the data is there, but it's just not being extracted correctly.

Terrific fix! I'll be cutting another alpha release shortly, which will include your work.

Your contributions to this project are much appreciated!