WA-RAILS7-004: Mongoid 8.x compatibility upgrade#743
WA-RAILS7-004: Mongoid 8.x compatibility upgrade#743kitcommerce wants to merge 2 commits intonextfrom
Conversation
- Widen mongoid gemspec from '~> 7.4' to '>= 7.4, < 9' (Mongoid 8.1.3+ formally adds Rails 7.0/7.1 support) - Replace all update_attributes/update_attributes! with update/update! across ~100 files (Mongoid 8.0 removes the deprecated methods) - Update Mongoid::QueryCache references to Mongo::QueryCache in 3 core files + tests (deprecated in 8.x, removed in 9.x) - Add load_defaults '7.5' shim in Configuration::Mongoid.load to preserve legacy Mongoid behavior on 8.x upgrade - Add docs/mongoid8-migration.md migration guide Closes #690
3a5ea85 to
17b7ab9
Compare
🔍 Simplicity Review — WA-RAILS7-004: Mongoid 8.x UpgradeVerdict: PASS_WITH_NOTES | Severity: LOW Overall AssessmentThis is a clean, well-scoped upgrade PR. The ~550 mechanical renames ( Two minor simplicity observations in the Finding 1 — LOW: Nested
|
🔒 Security Review — WA-RAILS7-004: Mongoid 8.x CompatibilityReviewer: Security SummaryThis PR introduces no new security vulnerabilities. The changes are mechanically sound from a security perspective. Two advisory notes are included for downstream awareness. Findings1. ✅ Mongoid Version Constraint Widening — No Known CVEs in Mongoid ODMRisk: NONE The gemspec change (
No action required. 2. ✅
|
Rails Conventions Review — WA-RAILS7-004Verdict: PASS_WITH_NOTES (severity: MEDIUM) The bulk of this PR is a mechanical, correct rename ( 🟡 MEDIUM —
|
✅ Wave 1 Complete — All Reviewers PASSEDAll four Wave 1 reviewers returned PASS_WITH_NOTES (no CHANGES_REQUIRED):
Wave 1 gate: PASS → Proceeding to Wave 2 (rails-security, database, test-quality). |
Rails Security Review — PR #743 (Mongoid 8.x Upgrade)Reviewer: rails-security (Wave 2) SummaryThis PR is a clean, mechanical upgrade with no security regressions. The ~550 Analysis1.
|
| # | Severity | Location | Finding |
|---|---|---|---|
| 1 | LOW | docs/mongoid8-migration.md |
Advisory: Consider adding a note about CVE-2025-14847 (MongoDB server, not ODM) — operators upgrading Mongoid gem may also need to verify their MongoDB server is patched. |
| 2 | LOW | core/lib/workarea/configuration/mongoid.rb |
Advisory: load_defaults('7.5') is correct as a transition shim. Document a future task to audit and adopt Mongoid 8 defaults explicitly, then remove the shim. |
Security Checklist
- No mass assignment changes (rename is 1:1 alias swap)
- No new user input handling paths
- No authentication/authorization changes
- No new query construction patterns (injection risk unchanged)
- No secrets or credentials in diff
- No CSRF protection changes
- No XSS surface changes
- Brakeman PASS confirmed
- No known Mongoid ODM CVEs for versions 7.4–8.x
{
"reviewer": "rails-security",
"verdict": "PASS_WITH_NOTES",
"severity": "LOW",
"summary": "Clean mechanical upgrade with no security regressions. All update_attributes renames are 1:1 behavioral equivalents. load_defaults 7.5 is the safe transition choice. No Mongoid ODM CVEs. Two LOW advisories: add CVE-2025-14847 (server-side) note to migration guide, and document future removal of load_defaults shim.",
"findings": [
{
"severity": "LOW",
"location": "docs/mongoid8-migration.md",
"description": "Advisory: Consider adding operator note about CVE-2025-14847 (MongoDB server) for teams upgrading their stack."
},
{
"severity": "LOW",
"location": "core/lib/workarea/configuration/mongoid.rb",
"description": "Advisory: load_defaults 7.5 shim is correct for transition. Document future task to audit Mongoid 8 defaults and remove shim."
}
]
}
🧪 Test Quality Review — WA-RAILS7-004 (Mongoid 8.x upgrade)Verdict: BLOCKED SummaryThis PR contains ~550 mechanical test renames and one middleware class assertion update. It does not contain tests that exercise Mongoid 8.x behavior, and critically, the PR itself confirms the full test suite was never run against Mongoid 8 ( Findings🚨 CRITICAL — No Mongoid 8 test runThe build gate passed rubocop only. The PR body explicitly states:
The This PR cannot merge until a Mongoid 8 test run completes. Wave 2 gate:build-passed is insufficient here — rubocop on Mongoid 7.4 tells us nothing about Mongoid 8 runtime behavior. 🔴 HIGH —
|
🗄️ Database Review — PR #743 (WA-RAILS7-004: Mongoid 8.x Upgrade)Reviewer: database QueryCache Correctness ✅The namespace migration from
All 3 production files and 2 test files are correctly updated. No remaining
|
| # | Severity | Location | Finding |
|---|---|---|---|
| 1 | MEDIUM | core/app/workers/workarea/index_release_schedule_change.rb:11 |
publish_at_was and publish_at_changed? used in Sidekiq callback lambdas evaluated post-save. In Mongoid 8, dirty tracking resets after save — worker may never fire. Recommend: use saved_change_to_publish_at? / publish_at_before_last_save. |
| 2 | LOW | docs/mongoid8-migration.md |
Migration guide missing attribute_was behavioral change docs for host apps using _was in after callbacks. |
| 3 | INFO | core/lib/workarea/configuration/mongoid.rb |
load_defaults ordering after load_configuration is safe — independent config namespaces. Wave 1 concern resolved. |
{
"reviewer": "database",
"verdict": "PASS_WITH_NOTES",
"severity": "MEDIUM",
"summary": "QueryCache migration, update_attributes renames, and load_defaults shim are all correct. One MEDIUM concern: Sidekiq callback dirty tracking (publish_at_was/publish_at_changed?) in IndexReleaseScheduleChange may silently break under Mongoid 8 due to post-save dirty state reset — not protected by load_defaults 7.5. Migration guide should also mention attribute_was behavioral changes for host apps. No blocking issues.",
"findings": [
{
"severity": "MEDIUM",
"file": "core/app/workers/workarea/index_release_schedule_change.rb",
"line": 11,
"issue": "publish_at_was/publish_at_changed? evaluated after run_callbacks(:save) — Mongoid 8 resets dirty state post-save, potentially preventing this worker from ever firing",
"recommendation": "Use saved_change_to_publish_at? and publish_at_before_last_save, or capture values in before_save"
},
{
"severity": "LOW",
"file": "docs/mongoid8-migration.md",
"issue": "Missing documentation of attribute_was behavioral change in after_* callbacks",
"recommendation": "Add section warning that _was methods return new values in after_* callbacks under Mongoid 8"
}
]
}
Closes #690
Summary
Makes Workarea compatible with Mongoid 8.x (required for Rails 7 support) while preserving backward compatibility shims for the 7.4→8 transition.
Minimum Mongoid version for Rails 7: 8.1.3 (formally added Rails 7.0/7.1 support).
Changes
1. Gemspec — Widen Mongoid dependency
2. Replace
update_attributes/update_attributes!(~550 occurrences, 102 files)Mongoid 8.0 removes these methods (deprecated since 7.x). Mechanically renamed:
.update_attributes(attrs)→.update(attrs).update_attributes!(attrs)→.update!(attrs)Files changed: core, admin, storefront, testing factories/helpers.
3. QueryCache:
Mongoid::QueryCache→Mongo::QueryCacheDeprecated in Mongoid 8.x; removed in Mongoid 9.x. Updated 3 core files + tests:
core/config/initializers/10_rack_middleware.rb— middleware registrationcore/app/queries/workarea/admin_search_query_wrapper.rb—clear_cache→clearcore/app/models/workarea/releasable.rb—uncachedblock4.
load_defaults '7.5'shim inConfiguration::Mongoid.loadPreserves legacy Mongoid 7.4 behavior (broken_* flags, compare_time_by_ms, legacy_attributes, etc.) when running under Mongoid 8+. Guards against version and method availability.
5. Migration guide:
docs/mongoid8-migration.mdComprehensive guide for host application developers covering all breaking changes, plugin compatibility risks, BigDecimal/Money field notes, and a Mongoid 9 upgrade preview.
Client Impact
HIGH — This is a hard cut. Mongoid 7.4 is incompatible with Rails 7 at the dependency level; both upgrades must happen together.
Breaking changes requiring host app action:
update_attributes/update_attributes!— Any host app or plugin code using these methods must be updated before running on Mongoid 8. Use the grep in the migration guide to find them.Mongoid::QueryCache— Replace withMongo::QueryCachein any custom middleware or model code.load_defaults "7.5"automatically; host app code relying on the new Mongoid 8 defaults must explicitly callMongoid.load_defaults("8.0")to opt in.Plugin ecosystem risk (HIGH — tracked separately):
mongoid-audit_log,mongoid-document_path,mongoid-encrypted, andmongoid-active_merchantmay require forking/patching for Mongoid 8 compatibility. Seedocs/mongoid8-migration.mdfor full details.Not breaking in Mongoid 8, but note for future Mongoid 9 upgrade:
around_*callbacks on embedded documents will be silently ignored (core is unaffected; plugins/host apps should audit)load_defaults "7.5"is rejected by Mongoid 9; must migrate to"8.0"before that upgradeTesting
bundle exec rake testincore/— no new Mongoid-related failuresReferences
docs/research/mongoid-upgrade-path.mddocs/mongoid8-migration.md