Skip to content
Snippets Groups Projects
Closed Using `return`, `break` or `throw` to exit a transaction block is deprecated without replacement
  • View options
  • Using `return`, `break` or `throw` to exit a transaction block is deprecated without replacement

  • View options
  • Closed Issue created by Thong Kuah
    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. (called from public_send at /srv/gitlab/lib/gitlab/database/load_balancing/connection_proxy.rb:127)

    -- https://log.gprd.gitlab.net/goto/437032f0-ecac-11ed-a017-0d32180b1390

    Screenshot_2023-05-07_at_7.52.35_PM

    This seems to have been introduced recently

    Refactoring

    In order to avoid break (and return) in Model.transaction blocks one could:

    • 1️⃣ Use next to commit a transaction and raise to rollback
    • 2️⃣ Extract code into methods and use guards (early return) instead
    • 3️⃣ : Refactor/restructure related conditionals in the block

    🆕 👮 Rails/TransactionExitStatement

    We can enable 👮 https://docs.rubocop.org/rubocop-rails/cops_rails.html#railstransactionexitstatement

    Edited by Peter Leitzen

    Linked items 0

  • Link items together to show that they're related or that one is blocking others.

    Activity

    • All activity
    • Comments only
    • History only
    • Newest first
    • Oldest first
    Loading Loading Loading Loading Loading Loading Loading Loading Loading Loading