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

Mongoid::Criteria#method_missing calling entries causes problems with big collections

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.5
    • Affects Version/s: None
    • Component/s: None
    • None

      Ruby 2.0 introduces the named parameters feature.
      When it's used in conjuction with varargs parameters, Ruby tries to
      call the #to_hash method in the arguments given when invoking the
      method.

      Mongoid::Criteria doesn't implement #to_hash, but it has a #method_missing
      that invokes entries, which fetches data from Mongodb. When this
      is performed with a huge database, it causes Mongodb to hang
      for a long time.

      Sample code that triggers the problem:

      class HugeCollection
        include Mongoid::Document
      end
      
      def a(*args, named_parameter: nil); end
      
      a(HugeCollection.all) # hangs forever
      

      A simpler way of showing the issue is:

      HugeCollection.all.anything_that_doesnt_exist # hangs forever
      

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

              Created:
              Updated:
              Resolved: