Patch run_callbacks instead of _run_commit_callbacks
#602
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR updates
IdentityCache's callback override mechanism to be compatible with updates to Rails' callback handling code, as of rails/rails@207a254. The change in Rails introduces a "fast path" for callbacks and no-ops the_run_#{callback}_callbacksmethods up until the point where a callback is actually defined, at which point Rails aliases_run_#{callback}_callbacksto a!version of the method.Rather than patching the ! version of the callbacks, we patch the
run_callbacksmethod. This way, we don't need to worry about callbacks potentially being defined before we include theIdentityCachegem, which can lead to Rails aliasing the non-patched version of the_run_commit_callbacks!methods. Plus,run_callbacksis public API, and it makes more sense for us to invalidate the cache any time callbacks are run (and not just when they're run via a call tocommitted!within Active Record transaction code.)Changes
run_callbacksinstead of_run_commit_callbacks: Rails 8.1 made_run_commit_callbacksa no-op and now uses run_commit_callbacks! internally (rails/rails@207a254).Overriding run_callbacks is more robust and avoids ordering issues when the IdentityCache module is included.
enabling safer rollout.
TODO: Remove
ignore_overridebefore shipping, after we verify the change doesn't cause any unintended side effects in Shopify's Core monolith.