Skip to content

MONGOID-5916 Deprecate the parameterless-not syntax - #6167

Merged
jamis merged 3 commits into
mongodb:masterfrom
jamis:5916-deprecate-not
Jul 31, 2026
Merged

MONGOID-5916 Deprecate the parameterless-not syntax#6167
jamis merged 3 commits into
mongodb:masterfrom
jamis:5916-deprecate-not

Conversation

@jamis

@jamis jamis commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Mongoid has historically supported the use of not in queries, without an argument. It effectively negates everything that comes after it:

Person.not.where(name: 'Bob')

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:

Person.not(name: 'Bob')

Or, it can even be a Criteria instance directly:

Person.not(Person.where(name: 'Bob'))

This even works with named scopes.

jamis added 2 commits July 29, 2026 10:04
Also, clean up and standardize the deprecation warnings a bit
@jamis
jamis requested a review from a team as a code owner July 29, 2026 16:33
@jamis
jamis requested review from comandeo-mongo and Copilot July 29, 2026 16:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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#not is 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 timeless and to silence deprecations where deprecated not syntax 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_at is nil (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.

Comment thread lib/mongoid/deprecable.rb
Comment thread spec/mongoid/criteria/queryable/selectable_logical_spec.rb
@jamis jamis added the feature Adds a new feature, without breaking compatibility label Jul 31, 2026
@jamis
jamis merged commit 8c976ba into mongodb:master Jul 31, 2026
76 checks passed
@jamis
jamis deleted the 5916-deprecate-not branch July 31, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Adds a new feature, without breaking compatibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants