Uploaded image for project: 'Red Hat 3scale API Management'
  1. Red Hat 3scale API Management
  2. THREESCALE-11946

Fix the order of after_commit callbacks

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • None
    • System
    • None
    • False
    • Hide

      None

      Show
      None
    • False
    • Not Started
    • Not Started
    • Not Started
    • Not Started
    • Not Started
    • Not Started

      In the upgrade to Rails 7.1, there was something that I missed. Probably because it's not in the generic release notes for [7.1\(https://guides.rubyonrails.org/7_1_release_notes.html].

      The change is that now order of the after_commit callbacks is as it is defined in the code, while prior to 7.1 the order was reversed. See https://guides.rubyonrails.org/active_record_callbacks.html#transactional-callback-ordering

      This specifically affected the callbacks on usage limits creation, where two callbacks are defined (and note also the comment that proves the privious statement):

      https://github.com/3scale/porta/blob/db92cc6ebe910229de333015975b204ced868273/app/lib/backend/model_extensions/usage_limit.rb#L11-L13

      So, after Rails upgrade, the order got reversed, and currently first update is performed, and then delete, so effectively any change in the usage limits deletes any limits in backend for that metric (thus making system and backend out of sync).

      This PR https://github.com/3scale/porta/pull/4151 temporarily restores the previous behavior, by setting

      config.active_record.run_after_transaction_callbacks_in_order_defined = false
      

      This issue is to remove this setting, and fix the order of all callbacks throughout the code base.

      Also, as part of this PR, make sure that the usage limits setting is covered by tests.

              Unassigned Unassigned
              rhn-support-dmayorov Daria Mayorova
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: