-
Notifications
You must be signed in to change notification settings - Fork 222
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
Failed transaction error in rails 4.1.8 and postgres #33
Comments
It's PostgreSQL related, it rejects any SQL statements after an error within a transaction. The workaround is to start a new nested transaction when creating the entry. You can do this by adding
If you wrap the block which retries the generation in shortened_url.rb (https://github.com/jpmcgrath/shortener/blob/master/app/models/shortener/shortened_url.rb#L64), then the retry should work. Could you create a pull request once you resolved this? |
try the psql branch: https://github.com/jpmcgrath/shortener/tree/psql |
@tomcartwrightuk did @mreinsch's suggestion fix your issue? If so, I will write a spec to exercise the transaction code and merge this is to develop for inclusion in an upcoming release. |
I actually tried that on a psql DB a while ago and it fixed it. The main challenge for a spec is that this issue will only occur with psql, not sqlite. |
According to this http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html, SQLite does support nested transactions:
|
They are supported, but only PostgreSQL needs it, as it aborts any transaction in which a failure occurred. So if you'd want to write a test for that, you'd need psql to really reproduce the issue. |
Gotcha. |
This is solved in #95 |
We are using rails 4.1.8 and Postgres and are receiving the following error when the unique index on the unique_key field is violated:
Is this a PG specific error? Has anyone seen it before? As a short term fix we are wrapping our call to
ShortenedUrl.generate
in a rescue block - it's not pretty.The text was updated successfully, but these errors were encountered: