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

Unexpected exception when using a "destructive" field

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 7.0.0, 6.2.1
    • Affects Version/s: 6.2.0
    • Component/s: None
    • None

      I have an application to reproduce this issue over here: https://github.com/radar/mong

      I have an older legacy application which I'm trying to upgrade to Rails 5 & Mongoid 6.2.0. We have a model called "Survey" which has a field called "options". Mongoid seems to choke on this, saying:

      {{/Users/ryanbigg/.gem/ruby/2.3.1/gems/mongoid-6.2.0/lib/mongoid/errors/invalid_field.rb:44:in `instance_method': undefined method `options' for class `Survey' (NameError)
      from /Users/ryanbigg/.gem/ruby/2.3.1/gems/mongoid-6.2.0/lib/mongoid/errors/invalid_field.rb:44:in `origin'
      from /Users/ryanbigg/.gem/ruby/2.3.1/gems/mongoid-6.2.0/lib/mongoid/errors/invalid_field.rb:22:in `initialize'
      from /Users/ryanbigg/.gem/ruby/2.3.1/gems/mongoid-6.2.0/lib/mongoid/fields/validators/macro.rb:75:in `new'}}

      I tracked the error back to https://github.com/mongodb/mongoid/blob/master/lib/mongoid/fields/validators/macro.rb#L75 and that's what let me know what the "real" exception is here.

      I think an exception should be raised something along the lines of "options is an invalid field because <x, y, z>" rather than this weird exception.

      Thank you for your time!

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            ryanbigg Ryan Bigg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: