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

Rep.update returning ok with if: :exists while no record exists and Cassandrax returns false applied #4

Open
erobit opened this issue Jan 26, 2017 · 1 comment
Assignees

Comments

@erobit
Copy link

erobit commented Jan 26, 2017

BTW great job with this package!

I'm having issues with performing Repo.update(user, if: :exists) and having {:ok, %User{...}} returned even though the record does not exist and no updates are applied in Cassandra.

As you can see in the adapter prepare_result method, false/applied returning :ok

{[false | row], [_ | cols], :nothing} -> {:ok, Enum.zip(cols, row)}

It's also not clear from the update function signature how to return an :error
https://github.com/elixir-ecto/ecto/blob/v2.1.3/lib/ecto/adapter.ex#L172

Basically the changeset values are being applied instead of an :error being returned. Do you have some insight?

@vintikzzz
Copy link
Owner

Hi, it is quite tricky situation right here. According to https://github.com/elixir-ecto/ecto/blob/v2.1.3/lib/ecto/adapter.ex#L172 it is possible to return {:invalid, constraints}, but while doing Repo.update(user, if: :exists) we don't really hit any constraint.

I can suggest only to use Repo.update!(user, if: :exists) instead for right now.

Can you propose better solution?

@vintikzzz vintikzzz self-assigned this Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants