scenic
scenic copied to clipboard
PG::NoActiveSqlTransaction: ERROR: SAVEPOINT can only be used in transaction blocks
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
Can you give us more information? What migration are you running? What is the SQL? What stacktrace do you get?
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 ?
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 raise
s 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.
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.