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

Mongoid 9 breaks store_in lambda options

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Ruby Drivers
    • 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?

      Mongoid 9 introduced a regression where passing lambdas to store_in options raises an error when trying to persist a document. This is explicitly mentioned in the docs as a feature (https://www.mongodb.com/docs/mongoid/current/reference/persistence-configuration/#document-storage).

      Sample code

      # file: store_in_proc_issue.rb
      require "bundler/inline"
      
      gemfile do
        source "https://rubygems.org"
      
        # Include desired version when testing
        # gem "mongoid", "~> 8.0"
        # gem "mongoid", "~> 9.0"
      end
      
      Mongoid.configure do |config|
        config.clients.default = {
          hosts: ["localhost:27017"],
          database: "foo",
        }
      end
      
      class Foo
        include Mongoid::Document
      
        store_in database: ->{ "foo" }, client: ->{ :bar }
      end
      
      puts "Mongoid: #{Mongoid::VERSION}"
      puts Foo.create
      

      =>

      Mongoid: 8.1.5
      #<Foo:0x00000001255bf240>
      
      Mongoid: 9.0.1
      :bar
      :bar
      :bar
      /mongo-2.20.1/lib/mongo/operation/result.rb:364:in `raise_operation_failure': [73:InvalidNamespace]: '.' is an invalid character in the database name: #<Proc:0x000000012499b928 mongoid_proc_issue.rb:21 (lambda)> (on localhost:27017, legacy retry, attempt 1) (Mongo::Error::OperationFailure)
      

      I'm pretty sure the mongo backtrace is a red herring and the issue stems from mongoid.

            Assignee:
            jamis.buck@mongodb.com Jamis Buck
            Reporter:
            asgerb Asger Behncke Jacobsen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: