-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.4
-
Component/s: None
-
None
If a MongoClient is initialized with _connect=False, and the first operation on the client is an update or remove, the client throws AutoReconnect("not master").
The bug does not manifest if the first operation is an insert, or if the client is a MongoReplicaSetClient.
The cause is: Collection calls client._ensure_connected(True) before doing an insert or command, but fails to do so before doing an update or remove. If the client is a MongoReplicaSetClient, the client calls self.__find_primary() before attempting to send the message, but MongoClient does not.
Collection should call _ensure_connected before an update or remove, the same as insert, in order to determine the wire protocol version. In the process, it will also avoid the "not master" error.