Skip to content

fix: #documents according to Mongoid 8.1 specification - #16

Closed
leamotta wants to merge 2 commits into
mongoid:mongoid7from
leamotta:mongoid8.1
Closed

leamotta wants to merge 2 commits into
mongoid:mongoid7from
leamotta:mongoid8.1

Conversation

@leamotta

Copy link
Copy Markdown

Summary

Mongoid 8.1 changed storage_options from a cattr_accessor (real @@ class variable) to a class_attribute (backed by singleton methods). The #documents method writes the dynamic snapshot class's storage with klass.class_variable_set :@@storage_options, ..., which silently no-ops under 8.1. The variable gets set but Mongoid never reads it. The snapshot class falls back to default storage options and queries blow up with [73:InvalidNamespace].

Fix

Replace the class_variable_set call with the public store_in API, which routes through Mongoid's official writer and works under both cattr_accessor (≤ 8.0) and class_attribute (≥ 8.1):

store_in(client:, collection:) has been the stable public API since Mongoid 3.0, so this is backwards-compatible with Mongoid 6, 7, 8.0, and 8.1.

Repro

Under Mongoid 8.1, any query against a snapshot collection (e.g. MyIndex.latest_or_new.documents("output").where(...)) raises Mongo::Error::OperationFailure: [73:InvalidNamespace].

References

@dblock

dblock commented May 26, 2026

Copy link
Copy Markdown

We need to get CI back going in this project, care to migrate Travis CI into GHA first in a separate PR?

@dblock

dblock commented Oct 16, 2026

Copy link
Copy Markdown

Thank you @leamotta for identifying the Mongoid 8.1 storage-options change. The public klass.store_in client: session_id, collection: collection_name fix is already on master via #17 (commit 9732a29) and was released in 1.3.3. The existing custom-database and cross-thread integration specs exercise the affected snapshot queries, and current CI includes Mongoid 8 and 9. Closing this as already shipped, not rejecting the fix.

Posted by an AI on behalf of @dblock.

@dblock dblock closed this Oct 16, 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