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

UserWarning with read preference and command using direct connection

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 2.8.1
    • Affects Version/s: 2.7
    • Component/s: None
    • Labels:
    • Minor Change

      Beginning with PYTHON-577, database.command raises UserWarning if a read preference is set but the command doesn't obey read preferences.

      >>> from pymongo import MongoClient
      >>> from pymongo import ReadPreference
      >>> client = MongoClient(read_preference=ReadPreference.SECONDARY_PREFERRED)
      >>> result = client.test.command("dbhash")
      __main__:1: UserWarning: dbhash does not support SECONDARY_PREFERRED read preference and will be routed to the primary instead.

      It doesn't matter whether the server is a primary, secondary, or whatever. The warning is only raised once in the process lifetime.

      The warning's intended for MongoReplicaSetClient connected to a primary and some secondaries, to warn you that you might think you're distributing a command to secondaries / all members, but in fact you always run it on the primary. But in the direct-connection case the warning is spurious.

      This conflicts with an overloaded meaning of read preference, which is "set the slaveOkay wire protocol bit." ("slave_okay=True" used to be a good way to express this for direct connections.)

      Two options:
      1. Close wontfix. PyMongo 3 implements the Server Selection Spec, which obviates this bug.
      2. Don't raise this UserWarning if the MongoClient is a direct connection.

            bernie@mongodb.com Bernie Hackett
            jesse@mongodb.com A. Jesse Jiryu Davis
            0 Vote for this issue
            3 Start watching this issue