Skip to content

[PPS-27689] Support Rails 8.1 by widening activesupport/activemodel upper bound to < 8.2 - #1

Closed
gloox wants to merge 4 commits into
8.1-stable-scfrom
PPS-27689-support-rails-8-1
Closed

gloox wants to merge 4 commits into
8.1-stable-scfrom
PPS-27689-support-rails-8-1

Conversation

@gloox

@gloox gloox commented Oct 13, 2026

Copy link
Copy Markdown

No description provided.

gloox and others added 4 commits October 13, 2026 14:26
…pper bound to < 8.2

Co-authored-by: Cursor <cursoragent@cursor.com>
… 8.0.0

Co-authored-by: Cursor <cursoragent@cursor.com>
…redefine 4-arg signature

Widening the activesupport/activemodel upper bound to < 8.2 allows Bundler
to resolve activesupport versions (8.0.3+, 8.1.x) whose
ActiveSupport::ClassAttribute.redefine signature gained a required
namespaced_name parameter (owner, name, namespaced_name, value), replacing
the old (owner, name, value) signature. Mongoid's custom
discriminator_key= override called redefine directly with the old 3-arg
signature, raising ArgumentError: wrong number of arguments (given 3,
expected 4) whenever a newer activesupport was loaded.

Detect the installed redefine arity and call it with the namespaced_name
Rails' own class_attribute macro uses (__class_attr_discriminator_key) when
the new signature is present, falling back to the old signature otherwise.
The previous fix addressed the ArgumentError from
ActiveSupport::ClassAttribute.redefine's new 4-arg signature in Rails
8.1, but didn't actually fix discriminator_key propagation.

class_attribute :discriminator_key defines a reader backed by a
private __class_attr_discriminator_key attribute, but that reader is
immediately overwritten by 'delegate :discriminator_key, to: ::Mongoid'
right after, in the same included block. So updating the private
attribute via ActiveSupport::ClassAttribute.redefine's new signature
had no effect on the actual (delegate-based) reader in use.

Prior to Rails 8.1, ActiveSupport::ClassAttribute.redefine(owner, name,
value) worked differently: it redefined the public reader method
directly on owner's singleton class, which happened to bypass this
issue entirely. Mimic that directly and simply, independent of
ActiveSupport::ClassAttribute's internal storage mechanism, so it
works consistently across versions and subclasses still inherit the
value through normal Ruby method lookup.

Co-authored-by: Cursor <cursoragent@cursor.com>
@DiljotSG

Copy link
Copy Markdown

It would be nice if we can drop the mongoid fork, and I think it's possible. Two of our four commits (the touch and created_at fixes) are already in the latest release, 9.1.1. The other two change child validation. Upstream added that fix and then reverted it for performance reasons, so if we still need it we can override it in an initializer instead of keeping a fork.

Here are the gems we should bump on your rails upgrade PR

  • mongoid → ~> 9.1.1 (fits our activemodel 8.0, mongo 2.21 and bson 5)
  • carrierwave-mongoid 1.4.0 → 1.5.0 and mongoid-grid_fs 2.5.0 → 2.6.0 (current versions cap mongoid below 9)
  • Worth bumping: mongoid-history 0.9.0, mongoid_paranoia 0.7.0

@gloox

gloox commented Oct 23, 2026

Copy link
Copy Markdown
Author

Superseded by #2 (Mongoid 8.1.13 with the same activemodel < 8.2 widening; supply_chain moves to it in getaroom/supply_chain#5175). Branch PPS-27689-support-rails-8-1 is kept for now because getaroom/supply_chain#5158 still installs from it.

@gloox gloox closed this Oct 23, 2026
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.

2 participants