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

PG::NoActiveSqlTransaction: ERROR: SAVEPOINT can only be used in transaction blocks #323

Open
drselump14 opened this issue Feb 4, 2021 · 4 comments

Comments

@drselump14
Copy link

Get this stranger error when trying to update the materialized view.

It seems that adapter prevents any usage of SAVEPOINT but for transactions.

Any help would be appreciated

@derekprior
Copy link
Contributor

Can you give us more information? What migration are you running? What is the SQL? What stacktrace do you get?

@stem
Copy link

stem commented Mar 19, 2021

Hello,

I've encountered the same issue.

In my case, we're using the doctolib/safe-pg-migrations gem, which automatically disable transactions.
Wrapping my migration in a

ActiveRecord::Base.connection.transaction do
end

block fixed the problem and everything run smoothly.

As this gem assumes that its run in a transaction, maybe it could wrap itself into one if necessary. What do you think ?

@derekprior
Copy link
Contributor

I don't think i want to sneakily renable transactions if the user explicitly decided not to use them for the migration (either themselves or by choosing a gem that does it for them). I think I'd be more likely to accept a patch that raises when IndexReapplication is used in a context where a transaction is not currently running. That would not be a behavior change as the migration would still fail, but the error message could tell people what's going on.

@stem
Copy link

stem commented Mar 19, 2021

Makes perfect sense !

I guess I did not think about that 'cause I've re-enabled the transaction on my migration 😅

For what it's worth, I think the check should be done before making any change in the database, as if the migration fails after dropping a view (my use case today) and is not in a transaction, the view is really gone.

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

3 participants