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

First/Last failures when empty hash passed as criteria

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.5.3
    • Affects Version/s: 7.5.0
    • Component/s: None
    • None

      This appears to be a regression from MONGOID-4998 as it only affects Mongoid 7.5+, but works with Mongoid <= 7.4:

      # replace with '7.5' to validate failure
      VERSION_TO_TEST = '7.4'
      
      require 'bundler/inline'
      
      gemfile do
        source 'https://rubygems.org'
        
        gem 'mongoid', VERSION_TO_TEST
      end
      
      Mongoid.configure.clients.default = { uri: "mongodb+srv://..." }
      
      class Test
        include Mongoid::Document
        field :name
      
        def self.go!
          t = self.create(name: "hello")
          # the {} parameter make the code crash on 7.5, not on 7.4
          puts "Testing with #{Mongoid::VERSION}"
          puts Test.where(name: "hello").first({}) 
        end
      end
      
      Test.go!
      # => KeyError: key not found: :id_sort
      

            Assignee:
            jamis.buck@mongodb.com Jamis Buck
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: