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

Loss of significant error messages #1

Closed
stavro opened this issue Oct 27, 2017 · 3 comments
Closed

Loss of significant error messages #1

stavro opened this issue Oct 27, 2017 · 3 comments

Comments

@stavro
Copy link

stavro commented Oct 27, 2017

Wrapping all calls to insert, update, etc causes valuable information to be lost about normal database transactions.

With a schema that uses Changeset.foreign_key_constraint/3 or Changeset.no_assoc_constraint, the messages are lost.

def prepare_delete(category) do
  category
  |> change
  |> no_assoc_constraint(:topics)
end



# Without using ExAudit.Repo

Category
|> Repo.get(id)
|> Category.prepare_delete
|> Repo.delete

# {:error,
#  #Ecto.Changeset<action: :delete, changes: %{},
#   errors: [topics: {"are still associated with this entry", []}],
#   data: #Category<>, valid?: false>}


# Using ExAudit.Repo

Category
|> Repo.get(id)
|> Category.prepare_delete
|> Repo.delete

# {:error, :rollback}

I realize this is not a straightforward (or even possible) thing to fix, but it should be very well documented that database errors and constraint messages are lost. I have a few places where there are multiple database-enforced constraints, and when using the provided Repo module, I have no way of knowing which constraint failed

@narrowtux
Copy link
Contributor

Seems like Repo.transaction will return {:error, :rollback} all the time, I thought returning the original return value of the wrapped repo function would suffice. I'm looking into alternatives, since I really want everything to work like before.

@narrowtux
Copy link
Contributor

In the hopes that Ecto.Multi will not lose the error messages, I rewrote my transaction code to use a multi. Now I've just got to write a test

@narrowtux
Copy link
Contributor

Fixed in 0.3.1 @stavro

narrowtux pushed a commit that referenced this issue Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants