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

Exception message claims where without arguments is allowed, but it is not

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 7.1.0
    • Component/s: Query
    • None

      In Mongoid 7.1 passing an explicit nil to where is not allowed. When this is done, the following message is produced:

      irb(main):002:0> Band.where(nil)
      Traceback (most recent call last):
              2: from (irb):1
              1: from (irb):2:in `rescue in irb_binding'
      Mongoid::Errors::CriteriaArgumentRequired ()
      message:
        Calling Criteria methods with nil arguments is not allowed.
      summary:
        Arguments to Criteria methods cannot be nil, and most Criteria methods require at least one argument. Only logical operations (and, or, nor and not), `all' and `where' can be called without arguments. The method that was called with nil argument was: where.
      resolution:
        Invoke Criteria methods with non-nil arguments or omit the respective invocations.
      

      This message says that argument-less where is allowed as a special case, but it is not:

      irb(main):003:0> Band.where     
      Traceback (most recent call last):
              2: from (irb):2
              1: from (irb):3:in `rescue in irb_binding'
      ArgumentError (wrong number of arguments (given 0, expected 1))
      

      There are two functions called `where` in the code base, and the one in Criteria has required an argument in 7.0 also thus this is not a compatibility break. However the exception message appears to suggest an API that does not exist and this should be remedied.

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: