Accessing Mongoid object[nil] raises undefined method `include?' for nil:NilClass

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Unknown
    • 8.1.6, 9.0.1
    • Affects Version/s: 8.0.3, 8.1.4
    • Component/s: None
    • None
    • None
    • Fully Compatible
    • Ruby Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      From github discussion: https://github.com/mongodb/mongoid/discussions/5540

      We are seeing this behavior in 8.1.4

      record = Person.first
      record[nil]
      undefined method `include?' for nil:NilClass      string.include?(".")
                  ^^^^^^^^^
      /usr/local/bundle/gems/mongoid-8.1.4/lib/mongoid/attributes.rb:272:in `hash_dot_syntax?': undefined method `include?' for nil:NilClass
            
      string.include?(".")
                  
      ^^^^^^^^^ (NoMethodError)
          
      from /usr/local/bundle/gems/mongoid-8.1.4/lib/mongoid/attributes.rb:297:in `read_raw_attribute'
          
      from /usr/local/bundle/gems/mongoid-8.1.4/lib/mongoid/attributes.rb:88:in `read_attribute'
      

      I can submit a PR to raise a more helpful Mongoid::Errors::UnknownAttribute instead

              Assignee:
              Jamis Buck
              Reporter:
              Dan Healy
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: