Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different casting on creation and retrieving from db #116

Closed
KernelMadness opened this issue Oct 2, 2019 · 4 comments
Closed

Different casting on creation and retrieving from db #116

KernelMadness opened this issue Oct 2, 2019 · 4 comments
Labels

Comments

@KernelMadness
Copy link

I think this commit introduced a bug.

MyApp.Records.create_record(%{amount: "$42"})

{:ok,
 %MyApp.Records.Records{
   __meta__: #Ecto.Schema.Metadata<:loaded, "records">,
   amount: 4200,
   id: 1,
   inserted_at: ~N[2019-10-02 16:30:32],
   updated_at: ~N[2019-10-02 16:30:32]
 }}

amount is 4200

MyApp.Records.list_records()

[
  %MyApp.Records.Record{
    __meta__: #Ecto.Schema.Metadata<:loaded, "records">,
    amount: %Money{amount: 4200, currency: :USD},
    id: 1,
    inserted_at: ~N[2019-10-02 16:30:32],
    updated_at: ~N[2019-10-02 16:30:32]
  }
]

amount is %Money{amount: 4200, currency: :USD}

This behaviour makes tests like this always fail

test "get_record!/1 returns the record with given id" do
  record = record_fixture()
  assert Records.get_record!(record.id) == record
end
@joshprice
Copy link

Have seen this as well in our test suite

@cdvv7788
Copy link

Maybe related to #118

@Nitrino
Copy link
Member

Nitrino commented Oct 16, 2019

This is a hack to get validations to work, but I agree with you, the structures after casting and loading from the database, should be same.
So this is a bug and we should abandon validations in favour of valid cast

@Nitrino
Copy link
Member

Nitrino commented Oct 28, 2019

Fixed in v1.6.1

@Nitrino Nitrino closed this as completed Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants