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

DEPRECATION WARNING: Using return, break or throw to exit a transaction block #2197

Open
bobyin opened this issue Nov 23, 2021 · 3 comments
Open
Labels

Comments

@bobyin
Copy link

bobyin commented Nov 23, 2021

Hi

We hit this problem when upgrade rails to 6.1.4, found the error! function throw it, please help. Thanks

DEPRECATION WARNING: Using return, break or throw to exit a transaction block is
deprecated without replacement. If the throw came from
Timeout.timeout(duration), pass an exception class as a second
argument so it doesn't use throw to abort its block. This results
in the transaction being committed, but in the next release of Rails
it will rollback.

Screen Shot 2021-11-23 at 10 12 57 AM

@dblock dblock added the bug? label Nov 23, 2021
@goatandsheep
Copy link

i'm not sure this code is part of ruby-grape anymore

@houhoulis
Copy link

houhoulis commented Mar 4, 2024

@goatandsheep It seems like the code is in grape, at https://github.com/ruby-grape/grape/blob/master/lib/grape/dsl/inside_route.rb#L164-L168:

  def error!(message, status = nil, additional_headers = nil)
    status = self.status(status || namespace_inheritable(:default_error_status))
    headers = additional_headers.present? ? header.merge(additional_headers) : header
    throw :error, message: message, status: status, headers: headers
  end

I'm getting this warning in Rails 7.1:

DEPRECATION WARNING: A transaction is being rolled back because the transaction block was
exited using `return`, `break` or `throw`.
In Rails 7.2 this transaction will be committed instead.
To opt-in to the new behavior now and suppress this warning
you can set:

  Rails.application.config.active_record.commit_transaction_on_non_local_return = true

Even if I set commit_transaction_on_non_local_return to false, I'm not seeing where that has an effect in Rails' future, in the main branch. And the commit_transaction_on_non_local_return config option itself states it will be removed in Rails 7.3.

Can this be fixed so that error!() stops a transaction? Should instead the README state that error()! used to roll back a transaction, but it won't do that in Rails 7.2+?

@dblock
Copy link
Member

dblock commented Mar 5, 2024

Someone who understands what Rails is trying to accomplish here should pitch in ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants