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

#find throwing BSON::InvalidObjectId instead of DocumentNotFound

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      Today after upgrading to mongoid 2.4.0 one spec started to fail, now #find throws BSON::InvalidObjectId instead of DocumentNotFound:

      require 'bundler'
      Bundler.require
      
      Mongoid.configure do |config|
        config.master = Mongo::Connection.new.db("godfather")
      end
      
      class Foo
        include Mongoid::Document
      end
      
      begin
        Foo.find('1234')
      rescue Mongoid::Errors::DocumentNotFound
        puts "Document not found."
        exit 0
      end
      
      exit -1
      

      Running git bisect I've found that the following checkin introduced this problem:

      1011f8d937ec8b0799564bec7c2c0fb8e42eca2b is the first bad commit
      commit 1011f8d937ec8b0799564bec7c2c0fb8e42eca2b
      Author: Durran Jordan <durran@gmail.com>
      Date: Sat Dec 3 11:38:10 2011 +0100

      Convert params to Model.find(id) to whatever the _id field type is defined as, no matter what the type. Closes MONGOID-1381.

      Can you confirm this is a bug?

      Thanks!

            Assignee:
            Unassigned Unassigned
            Reporter:
            tanob tanob
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: