Skip to content

Commit 11752ed

Browse files
authored
PYTHON-2899 Remove code for MongoDB <= 3.4 (mongodb#729)
Remove unneeded memoryview to bytes conversion.
1 parent 88e744d commit 11752ed

32 files changed

+224
-1961
lines changed

pymongo/_cmessagemodule.c

Lines changed: 0 additions & 704 deletions
Large diffs are not rendered by default.

pymongo/aggregation.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ def _database(self):
8888
"""The database against which the aggregation command is run."""
8989
raise NotImplementedError
9090

91-
@staticmethod
92-
def _check_compat(sock_info):
93-
"""Check whether the server version in-use supports aggregation."""
94-
pass
95-
9691
def _process_result(self, result, session, server, sock_info, secondary_ok):
9792
if self._result_processor:
9893
self._result_processor(
@@ -104,9 +99,6 @@ def get_read_preference(self, session):
10499
return self._target._read_preference_for(session)
105100

106101
def get_cursor(self, session, server, sock_info, secondary_ok):
107-
# Ensure command compatibility.
108-
self._check_compat(sock_info)
109-
110102
# Serialize command.
111103
cmd = SON([("aggregate", self._aggregation_target),
112104
("pipeline", self._pipeline)])
@@ -117,8 +109,7 @@ def get_cursor(self, session, server, sock_info, secondary_ok):
117109
# - server version is >= 4.2 or
118110
# - server version is >= 3.2 and pipeline doesn't use $out
119111
if (('readConcern' not in cmd) and
120-
((sock_info.max_wire_version >= 4 and
121-
not self._performs_write) or
112+
(not self._performs_write or
122113
(sock_info.max_wire_version >= 8))):
123114
read_concern = self._target.read_concern
124115
else:
@@ -218,11 +209,3 @@ def _cursor_collection(self, cursor):
218209
# aggregate too by defaulting to the <db>.$cmd.aggregate namespace.
219210
_, collname = cursor.get("ns", self._cursor_namespace).split(".", 1)
220211
return self._database[collname]
221-
222-
@staticmethod
223-
def _check_compat(sock_info):
224-
# Older server version don't raise a descriptive error, so we raise
225-
# one instead.
226-
if not sock_info.max_wire_version >= 6:
227-
err_msg = "Database.aggregate() is only supported on MongoDB 3.6+."
228-
raise ConfigurationError(err_msg)

pymongo/auth.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,6 @@ def _authenticate_x509(credentials, sock_info):
455455
return
456456

457457
cmd = _X509Context(credentials).speculate_command()
458-
if credentials.username is None and sock_info.max_wire_version < 5:
459-
raise ConfigurationError(
460-
"A username is required for MONGODB-X509 authentication "
461-
"when connected to MongoDB versions older than 3.4.")
462458
sock_info.command('$external', cmd)
463459

464460

@@ -496,10 +492,8 @@ def _authenticate_default(credentials, sock_info):
496492
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-256')
497493
else:
498494
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
499-
elif sock_info.max_wire_version >= 3:
500-
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
501495
else:
502-
return _authenticate_mongo_cr(credentials, sock_info)
496+
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
503497

504498

505499
_AUTH_MAP = {

pymongo/bulk.py

Lines changed: 5 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
InvalidOperation,
3636
OperationFailure)
3737
from pymongo.message import (_INSERT, _UPDATE, _DELETE,
38-
_do_batched_insert,
3938
_randint,
4039
_BulkWriteContext,
4140
_EncryptedBulkWriteContext)
@@ -256,17 +255,6 @@ def gen_unordered(self):
256255

257256
def _execute_command(self, generator, write_concern, session,
258257
sock_info, op_id, retryable, full_result):
259-
if sock_info.max_wire_version < 5:
260-
if self.uses_collation:
261-
raise ConfigurationError(
262-
'Must be connected to MongoDB 3.4+ to use a collation.')
263-
if self.uses_hint:
264-
raise ConfigurationError(
265-
'Must be connected to MongoDB 3.4+ to use hint.')
266-
if sock_info.max_wire_version < 6 and self.uses_array_filters:
267-
raise ConfigurationError(
268-
'Must be connected to MongoDB 3.6+ to use arrayFilters.')
269-
270258
db_name = self.collection.database.name
271259
client = self.collection.database.client
272260
listeners = client._event_listeners
@@ -283,7 +271,7 @@ def _execute_command(self, generator, write_concern, session,
283271
('ordered', self.ordered)])
284272
if not write_concern.is_server_default:
285273
cmd['writeConcern'] = write_concern.document
286-
if self.bypass_doc_val and sock_info.max_wire_version >= 4:
274+
if self.bypass_doc_val:
287275
cmd['bypassDocumentValidation'] = True
288276
bwc = self.bulk_ctx_class(
289277
db_name, cmd, sock_info, op_id, listeners, session,
@@ -358,24 +346,6 @@ def retryable_bulk(session, sock_info, retryable):
358346
_raise_bulk_write_error(full_result)
359347
return full_result
360348

361-
def execute_insert_no_results(self, sock_info, run, op_id, acknowledged):
362-
"""Execute insert, returning no results.
363-
"""
364-
command = SON([('insert', self.collection.name),
365-
('ordered', self.ordered)])
366-
concern = {'w': int(self.ordered)}
367-
command['writeConcern'] = concern
368-
if self.bypass_doc_val and sock_info.max_wire_version >= 4:
369-
command['bypassDocumentValidation'] = True
370-
db = self.collection.database
371-
bwc = _BulkWriteContext(
372-
db.name, command, sock_info, op_id, db.client._event_listeners,
373-
None, _INSERT, self.collection.codec_options)
374-
# Legacy batched OP_INSERT.
375-
_do_batched_insert(
376-
self.collection.full_name, run.ops, True, acknowledged, concern,
377-
not self.ordered, self.collection.codec_options, bwc)
378-
379349
def execute_op_msg_no_results(self, sock_info, generator):
380350
"""Execute write commands with OP_MSG and w=0 writeConcern, unordered.
381351
"""
@@ -441,62 +411,13 @@ def execute_no_results(self, sock_info, generator):
441411
raise ConfigurationError(
442412
'hint is unsupported for unacknowledged writes.')
443413
# Cannot have both unacknowledged writes and bypass document validation.
444-
if self.bypass_doc_val and sock_info.max_wire_version >= 4:
414+
if self.bypass_doc_val:
445415
raise OperationFailure("Cannot set bypass_document_validation with"
446416
" unacknowledged write concern")
447417

448-
# OP_MSG
449-
if sock_info.max_wire_version > 5:
450-
if self.ordered:
451-
return self.execute_command_no_results(sock_info, generator)
452-
return self.execute_op_msg_no_results(sock_info, generator)
453-
454-
coll = self.collection
455-
# If ordered is True we have to send GLE or use write
456-
# commands so we can abort on the first error.
457-
write_concern = WriteConcern(w=int(self.ordered))
458-
op_id = _randint()
459-
460-
next_run = next(generator)
461-
while next_run:
462-
# An ordered bulk write needs to send acknowledged writes to short
463-
# circuit the next run. However, the final message on the final
464-
# run can be unacknowledged.
465-
run = next_run
466-
next_run = next(generator, None)
467-
needs_ack = self.ordered and next_run is not None
468-
try:
469-
if run.op_type == _INSERT:
470-
self.execute_insert_no_results(
471-
sock_info, run, op_id, needs_ack)
472-
elif run.op_type == _UPDATE:
473-
for operation in run.ops:
474-
doc = operation['u']
475-
check_keys = True
476-
if doc and next(iter(doc)).startswith('$'):
477-
check_keys = False
478-
coll._update(
479-
sock_info,
480-
operation['q'],
481-
doc,
482-
upsert=operation['upsert'],
483-
check_keys=check_keys,
484-
multi=operation['multi'],
485-
write_concern=write_concern,
486-
op_id=op_id,
487-
ordered=self.ordered,
488-
bypass_doc_val=self.bypass_doc_val)
489-
else:
490-
for operation in run.ops:
491-
coll._delete(sock_info,
492-
operation['q'],
493-
not operation['limit'],
494-
write_concern,
495-
op_id,
496-
self.ordered)
497-
except OperationFailure:
498-
if self.ordered:
499-
break
418+
if self.ordered:
419+
return self.execute_command_no_results(sock_info, generator)
420+
return self.execute_op_msg_no_results(sock_info, generator)
500421

501422
def execute(self, write_concern, session):
502423
"""Execute operations.

0 commit comments

Comments
 (0)