Skip to content

Commit 7965906

Browse files
authored
PYTHON-3021 Send primaryPreferred when connected to standalone servers (#799)
1 parent 5b8b09a commit 7965906

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

pymongo/mongo_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1170,8 +1170,8 @@ def _socket_for_reads(self, read_preference, session):
11701170
# for topology type Single."
11711171
# Thread safe: if the type is single it cannot change.
11721172
topology = self._get_topology()
1173-
single = topology.description.topology_type == TOPOLOGY_TYPE.Single
11741173
server = self._select_server(read_preference, session)
1174+
single = topology.description.topology_type == TOPOLOGY_TYPE.Single
11751175

11761176
with self._get_socket(server, session) as sock_info:
11771177
secondary_ok = (single and not sock_info.is_mongos) or (

test/mockupdb/test_op_msg_read_preference.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,12 @@ def test(self):
158158
else:
159159
self.fail('unrecognized op_type %r' % operation.op_type)
160160
# For single mongod we send primaryPreferred instead of primary.
161-
if (expected_pref == ReadPreference.PRIMARY and self.single_mongod
162-
and operation.name != "command"):
161+
if expected_pref == ReadPreference.PRIMARY and self.single_mongod:
163162
expected_pref = ReadPreference.PRIMARY_PREFERRED
164-
with going(operation.function, client) as future:
163+
with going(operation.function, client):
165164
request = expected_server.receive()
166165
request.reply(operation.reply)
167166

168-
future() # No error.
169-
170167
self.assertEqual(expected_pref.document,
171168
request.doc.get('$readPreference'))
172169
self.assertNotIn('$query', request.doc)

0 commit comments

Comments
 (0)