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

Add persistence exception handling section #7

Merged
merged 7 commits into from
Apr 15, 2016
Merged

Conversation

psibi
Copy link
Member

@psibi psibi commented Mar 27, 2016

Let me know if this is not idiomatic. I did a related post regarding this on the mailing list: https://groups.google.com/forum/#!topic/yesodweb/MKEqVZdfam8

@@ -0,0 +1,82 @@
# Handling exception in persistence

Say, you have a code like this which throws exception:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps "throws an exception"?

@snoyberg
Copy link
Member

There's actually a problem with this. Once an exception is thrown within a transaction, most drivers will now consider the transaction in an invalid state, and therefore further changes will fail (I think). For example, I think the code you have here will fail for PostgreSQL (though unfortunately I can't easily test that at the moment).

@gregwebs
Copy link
Member

gregwebs commented Apr 4, 2016

Yes, generally speaking a DB exception must be caught outside the transaction because the DB will not necessarily throw an exception until commit in some cases (in this case imagine another thread doing the same insertion). In this particular example one could use the PersistUnique functionality. In general sometimes (and in this case) you can break up the transaction and catch errors outside it.

@psibi
Copy link
Member Author

psibi commented Apr 4, 2016

Yes, infact the code doesn't work with the PostgreSQL backend. I have been little occupied in my day job. Will update the PR by this week.

@psibi
Copy link
Member Author

psibi commented Apr 14, 2016

I have updated the code to handle it in a database like PostgreSQL. Have also added a helper function mapLiftSqlPersistMPool which is used for executing each transaction. Probably, it can be added to persistent if this is the proper way to do it.

@gregwebs
Copy link
Member

Looks better!

@snoyberg
Copy link
Member

LGTM too.

@psibi
Copy link
Member Author

psibi commented Apr 15, 2016

Thanks for the feedback, merging it.

@psibi psibi closed this Apr 15, 2016
@psibi psibi reopened this Apr 15, 2016
@psibi psibi merged commit fac2949 into yesodweb:master Apr 15, 2016
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

Successfully merging this pull request may close these issues.

3 participants