MONGOID-5916 Deprecate the parameterless-not syntax - #6167
Merged
Conversation
Also, clean up and standardize the deprecation warnings a bit
Contributor
There was a problem hiding this comment.
Pull request overview
This PR deprecates the parameterless Criteria#not syntax (where not negates the following query operations) and updates related specs and deprecation plumbing so legacy behavior can continue to be tested while emitting (or silencing) deprecation warnings.
Changes:
- Add a deprecation warning when
Selectable#notis called with no arguments. - Introduce a shared deprecator + deprecation warning helper with “warn once” guarding (plus a test reset hook).
- Update timeless and criteria specs to use block-based
timelessand to silence deprecations where deprecatednotsyntax is exercised.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/mongoid/criteria/queryable/selectable.rb | Emits a deprecation warning for #not when called without arguments; updates method docs/examples. |
| lib/mongoid/deprecable.rb | Adds Mongoid.deprecator, Mongoid.deprecation_warning, and a guarded “warn once” mechanism + test reset. |
| lib/mongoid/timestamps/timeless.rb | Switches timeless block-less deprecation to the shared Mongoid.deprecation_warning API with callsite adjustment. |
| spec/mongoid/criteria/queryable/selectable_logical_spec.rb | Silences deprecations in specs that validate deprecated parameterless-not behavior. |
| spec/mongoid/timestamps/timeless_spec.rb | Updates tests to use block-form timeless and resets deprecation-warning state for deterministic assertions. |
Comments suppressed due to low confidence (1)
spec/mongoid/timestamps/timeless_spec.rb:68
- This example description says the parent is created "with a timestamp" but the expectation asserts
created_atisnil(i.e. no timestamp). Updating the description will make the spec intention clearer.
Chicken.timeless { Chicken.create! }
end
it 'creates the parent with a timestamp' do
expect(chicken.created_at).to be_nil
end
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
comandeo-mongo
approved these changes
Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Mongoid has historically supported the use of
notin queries, without an argument. It effectively negates everything that comes after it:This syntax is ambiguous and results in confusing situations, so we've deprecated that syntax. It will be removed in a future major release of Mongoid.
Moving forward, please prefer passing an argument to
#not, which will be negated. This can be a Hash of conditions:Or, it can even be a Criteria instance directly:
This even works with named scopes.