Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4887

Queryable Selector with .or and DateTime fails (NotImplementedError)

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.1.2
    • Affects Version/s: 7.1.1
    • Component/s: Query
    • Labels:

      The following repro will fail on Linux (but not on OSX).

      Tested using Ruby 2.5, 2.6 and 2.7.

      # MONGOID-4887.rb
      require 'bundler/inline'
      
      gemfile do
        source 'https://rubygems.org'
      
        gem 'mongoid', '7.1.1'
        gem 'mongo', '2.11.4'
        gem 'rspec'
      end
      
      Mongoid.configure do |config|
        config.clients.default = {
          hosts: ['localhost:27017'],
          database: 'my_db'
        }
      end
      
      class Goal
        include Mongoid::Document
        include Mongoid::Timestamps
      end
      
      describe "Queryable Selector" do
        it ".or + Time.current should not fail" do
          expect { Goal.or(:created_at.gte => Time.current) }.to_not raise_error
        end
        it ".or + DateTime.current should not fail" do
          expect { Goal.or(:created_at.gte => DateTime.current) }.to_not raise_error
        end
        it ".where + Time.current should not fail" do
          expect { Goal.where(:created_at.gte => Time.current) }.to_not raise_error
        end
        it ".where + DateTime.current should not fail" do
          expect { Goal.where(:created_at.gte => DateTime.current) }.to_not raise_error
        end
      end
      

      1. Save to MONGOID-4887.rb
      2. Run with rspec -fd MONGOID-4887.rb

      OSX:

      Queryable Selector
        .or + Time.current should not fail
        .or + DateTime.current should not fail
        .where + Time.current should not fail
        .where + DateTime.current should not fail
      
      Finished in 0.00298 seconds (files took 0.98413 seconds to load)
      

      Linux:

      Queryable Selector
        .or + Time.current should not fail
        .or + DateTime.current should not fail (FAILED - 1)
        .where + Time.current should not fail
        .where + DateTime.current should not fail
      
      Failures:
      
        1) Queryable Selector .or + DateTime.current should not fail
           Failure/Error: expect { Goal.or(:created_at.gte => DateTime.current) }.to_not raise_error
           
             expected no Exception, got #<NotImplementedError: This method is not prepared to handle key being a Key and serializer being not nil> with backtrace:
               # /home/alex/.rvm/gems/ruby-2.7.1/gems/mongoid-7.1.1/lib/mongoid/criteria/queryable/selector.rb:127:in `block (2 levels) in evolve_multi'
               # /home/alex/.rvm/gems/ruby-2.7.1/gems/mongoid-7.1.1/lib/mongoid/criteria/queryable/selector.rb:102:in `each'
               # /home/alex/.rvm/gems/ruby-2.7.1/gems/mongoid-7.1.1/lib/mongoid/criteria/queryable/selector.rb:102:in `map'
               # /home/alex/.rvm/gems/ruby-2.7.1/gems/mongoid-7.1.1/lib/mongoid/criteria/queryable/selector.rb:102:in `block in evolve_multi'
               # /home/alex/.rvm/gems/ruby-2.7.1/gems/mongoid-7.1.1/lib/mongoid/criteria/queryable/selector.rb:101:in `map'
               # /home/alex/.rvm/gems/ruby-2.7.1/gems/mongoid-7.1.1/lib/mongoid/criteria/queryable/selector.rb:101:in `evolve_multi'
               # /home/alex/.rvm/gems/ruby-2.7.1/gems/mongoid-7.1.1/lib/mongoid/criteria/queryable/selector.rb:59:in `store'
               # /home/alex/.rvm/gems/ruby-2.7.1/gems/mongoid-7.1.1/lib/mongoid/criteria/queryable/mergeable.rb:198:in `block (2 levels) in _mongoid_add_top_level_operation'
               # /home/alex/.rvm/gems/ruby-2.7.1/gems/mongoid-7.1.1/lib/mongoid/criteria/queryable/mergeable.rb:191:in `each'
               # /home/alex/.rvm/gems/ruby-2.7.1/gems/mongoid-7.1.1/lib/mongoid/criteria/queryable/mergeable.rb:191:in `block in _mongoid_add_top_level_operation'
               # /home/alex/.rvm/gems/ruby-2.7.1/gems/mongoid-7.1.1/lib/mongoid/criteria/queryable/mergeable.rb:189:in `tap'
               # /home/alex/.rvm/gems/ruby-2.7.1/gems/mongoid-7.1.1/lib/mongoid/criteria/queryable/mergeable.rb:189:in `_mongoid_add_top_level_operation'
               # /home/alex/.rvm/gems/ruby-2.7.1/gems/mongoid-7.1.1/lib/mongoid/criteria/queryable/selectable.rb:622:in `or'
               # ./MONGOID-4887.rb:28:in `block (3 levels) in <top (required)>'
               # ./MONGOID-4887.rb:28:in `block (2 levels) in <top (required)>'
           # ./MONGOID-4887.rb:28:in `block (2 levels) in <top (required)>'
      
      Finished in 0.02295 seconds (files took 1.08 seconds to load)
      4 examples, 1 failure
      
      Failed examples:
      
      rspec ./MONGOID-4887.rb:27 # Queryable Selector .or + DateTime.current should not fail
      

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: