Skip to content

Conversation

@adrianna-chang-shopify
Copy link
Contributor

@adrianna-chang-shopify adrianna-chang-shopify commented Oct 24, 2025

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}_callbacks methods up until the point where a callback is actually defined, at which point Rails aliases _run_#{callback}_callbacks to a ! version of the method.

Rather than patching the ! version of the callbacks, we patch the run_callbacks method. This way, we don't need to worry about callbacks potentially being defined before we include the IdentityCache gem, which can lead to Rails aliasing the non-patched version of the _run_commit_callbacks! methods. Plus, run_callbacks is 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 to committed! within Active Record transaction code.)

Changes

  • Patch run_callbacks instead of _run_commit_callbacks: Rails 8.1 made _run_commit_callbacks a 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.
  • [Temporary] Add ignore_override parameter: Introduces a temporary compatibility flag to allow callers to bypass the cache expiration behavior. This provides backwards compatibility for existing code that calls run_callbacks directly,
    enabling safer rollout.

TODO: Remove ignore_override before shipping, after we verify the change doesn't cause any unintended side effects in Shopify's Core monolith.

@adrianna-chang-shopify
Copy link
Contributor Author

Tests for this pass locally for me with all three gemfiles.
CI seems to be borked: https://github.com/Shopify/identity_cache/actions/runs/18788007562/job/53611097875 (here's a no-op commit on a fresh branch that's failing CI)

if destroyed? || transaction_changed_attributes.present?
expire_cache
if ActiveRecord.version >= Gem::Version.new("7.1")
def run_callbacks(kind, type = nil, ignore_override: false)
Copy link
Member

@Edouard-chin Edouard-chin Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the ignore_override come from ?

I should RTFM

@byroot
Copy link
Contributor

byroot commented Jan 9, 2026

hey folks 👋 .

How did you deal this issues, are you running this branch in production? Because we're running into the same issue, so let me know if I can help get the PR over the finish line. Would be nice to have a identity_cache release that works with Rails 8.1.

@Edouard-chin
Copy link
Member

👋 We are indeed running this branch in production. We wanted to ensure the fix in this PR wouldn't have negative side effect before merging it and cutting a new release. With BFCM and deploy restrictions it delayed things a bit, but we should be able to merge this now since we confirm it works with no issue.

@adrianna-chang-shopify
Copy link
Contributor Author

👋 Hi, yes we've validated this works in production. My goal is to get this out today!

@byroot
Copy link
Contributor

byroot commented Jan 9, 2026

❤️

Ref: rails/rails@207a254

_run_commit_callbacks is now a no-op; Rails aliases it to a `run_commit_callbacks!` implementation.
We could patch the `!` version, but it can lead to issues depending on when callbacks are defined and
when the `IdentityCache` module is included. Overriding `run_callbacks` is a more robust solution.
@adrianna-chang-shopify adrianna-chang-shopify force-pushed the ac-fix-commit-callback-patch branch from eebc8d8 to 8c6a19f Compare January 9, 2026 16:29
@adrianna-chang-shopify
Copy link
Contributor Author

Failures are apparent on main too, so going to merge this and relase.

@adrianna-chang-shopify adrianna-chang-shopify merged commit d86056c into main Jan 9, 2026
3 of 5 checks passed
@adrianna-chang-shopify adrianna-chang-shopify deleted the ac-fix-commit-callback-patch branch January 9, 2026 16:40
@adrianna-chang-shopify
Copy link
Contributor Author

@byroot this is in the v1.6.4 release for your use :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants