Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-2749

Apply database's codec_options to db.command

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Backlog
    • Unknown
    • Resolution: Unresolved
    • None
    • None
    • None
    • None
    • Minor Change

    Description

      The Database.command method has this caveat:

              .. note:: :meth:`command` does **not** obey this Database's
                 :attr:`read_preference` or :attr:`codec_options`. You must use the
                 `read_preference` and `codec_options` parameters instead.
      

      This is often surprising to users since almost every other method does use codec_options.

      Another motivation is that after PYTHON-2245, the default uuidRepresentation will be changed to UNSPECIFIED. This combined with the current db.command behavior means that an app which explicitly sets uuidRepresentation when creating the MongoClient will still get an error when sending a UUID through db.command. Eg:

      >>> client = MongoClient(uuidRepresentation='standard')
      >>> client.admin.command('hello', uuidField=uuid.uuid4())
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/Users/shane/git/mongo-python-driver/pymongo/database.py", line 604, in command
          return self._command(sock_info, command, slave_ok, value,
        File "/Users/shane/git/mongo-python-driver/pymongo/database.py", line 486, in _command
          return sock_info.command(
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", line 730, in command
          self._raise_connection_failure(error)
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", line 714, in command
          return command(self, dbname, spec, slave_ok,
        File "/Users/shane/git/mongo-python-driver/pymongo/network.py", line 117, in command
          request_id, msg, size, max_doc_size = message._op_msg(
        File "/Users/shane/git/mongo-python-driver/pymongo/message.py", line 730, in _op_msg
          return _op_msg_uncompressed(
        File "/Users/shane/git/mongo-python-driver/bson/binary.py", line 243, in from_uuid
          raise ValueError(
      ValueError: cannot encode native uuid.UUID with UuidRepresentation.UNSPECIFIED. UUIDs can be manually converted to bson.Binary instances using bson.Binary.from_uuid() or a different UuidRepresentation can be configured. See the documentation for UuidRepresentation for more information.
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              shane.harvey@mongodb.com Shane Harvey
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: