Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-740

Write concern with nil values via MongoClient.from_uri

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.10.0
    • Affects Version/s: None
    • Component/s: None
    • None

      MongoClient.from_uri injects faulty :writeConcern => {:w=>1, :j=>nil, :fsync=>nil, :wtimeout=>nil} - note the nil values.
      Server 2.6-rc1 inserts successfully with the above write concern, but
      server 2.6-rc2 complains about this with the following message.

      mongo/db/write_concern_options.cpp:46:

                  return Status( ErrorCodes::FailedToParse, "j must be numeric or a boolean value" );
      

      Here's my recommended test to be added:
      test/functional/client_test.rb:147

        def test_from_uri_write_concern
          con = MongoClient.from_uri("mongodb://#{host_port}")
          db = con.db
          coll = db.collection('from-uri-test')
          assert_equal BSON::ObjectId, coll.insert({'a' => 1}).class
          [con, db, coll].each do |component|
            component.write_concern.each{|k,v| assert_not_nil(v, "should not have field #{k.inspect} with nil value")}
          end
        end
      

      output from rc1:

      $ ruby -Ilib -Itest test/functional/client_test.rb --name test_from_uri_write_concern
      ...
      Loaded suite test/functional/client_test
      Started
      F
      ===============================================================================
      Failure:
        should not have field :j with nil value.
        <nil> expected to not be nil.
      test_from_uri_write_concern(ClientTest)
      test/functional/client_test.rb:153:in `block (2 levels) in test_from_uri_write_concern'
      test/functional/client_test.rb:153:in `each'
      test/functional/client_test.rb:153:in `block in test_from_uri_write_concern'
      test/functional/client_test.rb:152:in `each'
      test/functional/client_test.rb:152:in `test_from_uri_write_concern'
           149:     db = con.db
           150:     coll = db.collection('from-uri-test')
           151:     assert_equal BSON::ObjectId, coll.insert({'a' => 1}).class
        => 152:     [con, db, coll].each do |component|
           153:       component.write_concern.each{|k,v| assert_not_nil(v, "should not have field #{k.inspect} with nil value")}
           154:     end
           155:   end
      ===============================================================================
      Finished in 0.006285 seconds.
      1 tests, 3 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
      0% passed
      

      output from rc2:

      $ ruby -Ilib -Itest test/functional/client_test.rb --name test_from_uri_write_concern
      ...
      Loaded suite test/functional/client_test
      Started
      E
      ===============================================================================
      Error: test_from_uri_write_concern(ClientTest)
        Mongo::OperationFailure: Database command 'insert' failed: j must be numeric or a boolean value
      /Users/gjm/10gen/mongo-ruby-driver/lib/mongo/db.rb:559:in `rescue in command'
      /Users/gjm/10gen/mongo-ruby-driver/lib/mongo/db.rb:555:in `command'
      /Users/gjm/10gen/mongo-ruby-driver/lib/mongo/collection_writer.rb:314:in `block in send_write_command'
      /Users/gjm/10gen/mongo-ruby-driver/lib/mongo/functional/logging.rb:55:in `block in instrument'
      /Users/gjm/10gen/mongo-ruby-driver/lib/mongo/functional/logging.rb:20:in `instrument'
      /Users/gjm/10gen/mongo-ruby-driver/lib/mongo/functional/logging.rb:54:in `instrument'
      /Users/gjm/10gen/mongo-ruby-driver/lib/mongo/collection_writer.rb:313:in `send_write_command'
      /Users/gjm/10gen/mongo-ruby-driver/lib/mongo/collection.rb:1076:in `send_write'
      /Users/gjm/10gen/mongo-ruby-driver/lib/mongo/collection.rb:419:in `insert'
      test/functional/client_test.rb:151:in `test_from_uri_write_concern'
           148:     con = MongoClient.from_uri("mongodb://#{host_port}")
           149:     db = con.db
           150:     coll = db.collection('from-uri-test')
        => 151:     assert_equal BSON::ObjectId, coll.insert({'a' => 1}).class
           152:     [con, db, coll].each do |component|
           153:       component.write_concern.each{|k,v| assert_not_nil(v, "should not have field #{k.inspect} with nil value")}
           154:     end
      ===============================================================================
      Finished in 0.009016 seconds.
      1 tests, 0 assertions, 0 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
      0% passed
      110.91 tests/s, 0.00 assertions/s
      

      Scanning our tests, it appears that we don't cover the case of creating mongo client from uri, then doing a write. So our current tests (not the above) pass on rc2.

      I think that the critical issue for us is that old Ruby driver version may have the same problem. The server release is imminent. If 2.6 releases, and old Ruby drivers have a write concern problem with from_uri, then our users will have a problem. I know that this is a problem with our Ruby gem 1.10.0.rc1. We'd have to go back to older gems to determine if they have the problem with 2.6-rc2.

            Assignee:
            gjmurakami Gary Murakami
            Reporter:
            gjmurakami Gary Murakami
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: