-
Type: Bug
-
Resolution: Done
-
Priority: Trivial - P5
-
Affects Version/s: 2.7
-
Component/s: None
-
None
-
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.
- is related to
-
SERVER-18073 Fix smoke.py to work with pymongo 3.0
- Closed