circles-learning-labs / ecto_adapters_dynamodb

DynamoDB adapter for Elixir's Ecto Database layer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

:source option doesnt work for query

AlexKovalevych opened this issue · comments

Steps to reproduce:

  1. Create a schema with source option:
  schema "User" do
    field :email :string, source: :Email
  end
  1. Insert at least one document to db with email = "test@example.com"
  2. Get that result from db. Actual result:
%User{email: nil}

Expected result:

%User{email: "test@example.com"}

Thank you for raising this issue. We're looking into it.

thanks. Actually, there is one more problem, connected to this one:

on insert, i got 2 fields inserted - both email and Email, but email is always nil. I expect email won't be inserted at all. Here is a PR: #3

For some reason, I wasn't able to run the tests, getting:

** (CompileError) test/adapter_state_eqc_test.exs:4: module :eqc_statem is not loaded and could not be found

Hey @AlexKovalevych, so the error about EQC is because we're using a tool called Erlang QuickCheck for some of our tests (http://quviq.com/) and unfortunately it requires a commercial license to use. I've been meaning to modify our test suite to skip over the EQC tests if it's not installed locally, but haven't gotten around to it yet. In the short term you could just try and locally remove the code that's erroring out, but I'll see if I can take a look at this tomorrow and get a real fix implemented.

As for the issue with the source option, it's something we'd like to support in our adapter but right now the code for it just isn't there, and we haven't needed that option at all since - in the projects we use this adapter for - all our database fields share the same name in DynamoDB and Ecto.

I don't think anyone here at Circles will have the time or the inclination to add support for source anytime soon, but I'm happy to leave this issue open for now. If you'd like to tackle it yourself we'd be happy to accept a pull request; I doubt it would be difficult to add, but like I said, it's just not something we have time for at the moment.

@nickelization thank you for you response, i'll work on PR then

@AlexKovalevych you might consider the function, custom_decode as a potential place to add the missing "sourced" fields -- just a suggestion, I'll leave it up to you.

Closing issue. Alex's PR merged, commit 19fdfd8.

@AlexKovalevych I just pushed up a fix to automatically skip over the EQC code if you don't have EQC installed. This should allow you to run the mix test target without hitting the issue you saw above; it won't run any of the property-based test code, but it will run the basic ExUnit checks. Let me know if you run into any other problems! (And feel free to submit any additional ExUnit tests you develop along the way as well - we could certainly use better test coverage.)