From 5590ddf50b0751ecbddd9c5919d76f2dba7bef11 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 31 Jan 2024 08:34:48 -0600 Subject: [PATCH] =?UTF-8?q?Revert=20"PYTHON-4018=20Clarify=20exactly=20wha?= =?UTF-8?q?t=20code/label=20fields=20drivers=20should=20ins=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 85b0c0e3c13cbb7c005147a95292185ca1fc4b1d. --- pymongo/mongo_client.py | 12 +- .../unified/insertOne-serverErrors.json | 322 +----------------- 2 files changed, 14 insertions(+), 320 deletions(-) diff --git a/pymongo/mongo_client.py b/pymongo/mongo_client.py index 5b4474a621..4991d59f10 100644 --- a/pymongo/mongo_client.py +++ b/pymongo/mongo_client.py @@ -83,7 +83,6 @@ PyMongoError, ServerSelectionTimeoutError, WaitQueueTimeoutError, - WriteConcernError, ) from pymongo.lock import _HAS_REGISTER_AT_FORK, _create_lock, _release_locks from pymongo.monitoring import ConnectionClosedReason @@ -2142,7 +2141,7 @@ def _retryable_error_doc(exc: PyMongoError) -> Optional[Mapping[str, Any]]: return None -def _add_retryable_write_error(exc: PyMongoError, max_wire_version: int, is_mongos: bool) -> None: +def _add_retryable_write_error(exc: PyMongoError, max_wire_version: int) -> None: doc = _retryable_error_doc(exc) if doc: code = doc.get("code", 0) @@ -2159,10 +2158,7 @@ def _add_retryable_write_error(exc: PyMongoError, max_wire_version: int, is_mong for label in doc.get("errorLabels", []): exc._add_error_label(label) else: - # Do not consult writeConcernError for pre-4.4 mongos. - if isinstance(exc, WriteConcernError) and is_mongos: - pass - elif code in helpers._RETRYABLE_ERROR_CODES: + if code in helpers._RETRYABLE_ERROR_CODES: exc._add_error_label("RetryableWriteError") # Connection errors are always retryable except NotPrimaryError and WaitQueueTimeoutError which is @@ -2396,14 +2392,12 @@ def _write(self) -> T: """ try: max_wire_version = 0 - is_mongos = False self._server = self._get_server() supports_session = ( self._session is not None and self._server.description.retryable_writes_supported ) with self._client._checkout(self._server, self._session) as conn: max_wire_version = conn.max_wire_version - is_mongos = conn.is_mongos if self._retryable and not supports_session: # A retry is not possible because this server does # not support sessions raise the last error. @@ -2414,7 +2408,7 @@ def _write(self) -> T: if not self._retryable: raise # Add the RetryableWriteError label, if applicable. - _add_retryable_write_error(exc, max_wire_version, is_mongos) + _add_retryable_write_error(exc, max_wire_version) raise def _read(self) -> T: diff --git a/test/retryable_writes/unified/insertOne-serverErrors.json b/test/retryable_writes/unified/insertOne-serverErrors.json index 89827fcf3f..77245a8197 100644 --- a/test/retryable_writes/unified/insertOne-serverErrors.json +++ b/test/retryable_writes/unified/insertOne-serverErrors.json @@ -3,16 +3,10 @@ "schemaVersion": "1.0", "runOnRequirements": [ { - "minServerVersion": "4.0", + "minServerVersion": "3.6", "topologies": [ "replicaset" ] - }, - { - "minServerVersion": "4.1.7", - "topologies": [ - "sharded" - ] } ], "createEntities": [ @@ -61,7 +55,16 @@ "description": "InsertOne succeeds after retryable writeConcernError", "runOnRequirements": [ { - "minServerVersion": "4.3.1" + "minServerVersion": "4.0", + "topologies": [ + "replicaset" + ] + }, + { + "minServerVersion": "4.1.7", + "topologies": [ + "sharded-replicaset" + ] } ], "operations": [ @@ -165,309 +168,6 @@ ] } ] - }, - { - "description": "RetryableWriteError label is added based on top-level code in pre-4.4 server response", - "runOnRequirements": [ - { - "minServerVersion": "4.2", - "maxServerVersion": "4.2.99", - "topologies": [ - "replicaset", - "sharded" - ] - } - ], - "operations": [ - { - "name": "failPoint", - "object": "testRunner", - "arguments": { - "client": "client0", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "insert" - ], - "errorCode": 189 - } - } - } - }, - { - "name": "insertOne", - "object": "collection0", - "arguments": { - "document": { - "_id": 3, - "x": 33 - } - }, - "expectError": { - "errorLabelsContain": [ - "RetryableWriteError" - ] - } - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "insert": "coll", - "documents": [ - { - "_id": 3, - "x": 33 - } - ] - }, - "commandName": "insert", - "databaseName": "retryable-writes-tests" - } - }, - { - "commandStartedEvent": { - "command": { - "insert": "coll", - "documents": [ - { - "_id": 3, - "x": 33 - } - ] - }, - "commandName": "insert", - "databaseName": "retryable-writes-tests" - } - } - ] - } - ], - "outcome": [ - { - "collectionName": "coll", - "databaseName": "retryable-writes-tests", - "documents": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - } - ] - } - ] - }, - { - "description": "RetryableWriteError label is added based on writeConcernError in pre-4.4 mongod response", - "runOnRequirements": [ - { - "minServerVersion": "4.2", - "maxServerVersion": "4.2.99", - "topologies": [ - "replicaset" - ] - } - ], - "operations": [ - { - "name": "failPoint", - "object": "testRunner", - "arguments": { - "client": "client0", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "insert" - ], - "writeConcernError": { - "code": 91, - "errmsg": "Replication is being shut down" - } - } - } - } - }, - { - "name": "insertOne", - "object": "collection0", - "arguments": { - "document": { - "_id": 3, - "x": 33 - } - }, - "expectError": { - "errorLabelsContain": [ - "RetryableWriteError" - ] - } - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "insert": "coll", - "documents": [ - { - "_id": 3, - "x": 33 - } - ] - }, - "commandName": "insert", - "databaseName": "retryable-writes-tests" - } - }, - { - "commandStartedEvent": { - "command": { - "insert": "coll", - "documents": [ - { - "_id": 3, - "x": 33 - } - ] - }, - "commandName": "insert", - "databaseName": "retryable-writes-tests" - } - } - ] - } - ], - "outcome": [ - { - "collectionName": "coll", - "databaseName": "retryable-writes-tests", - "documents": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - }, - { - "_id": 3, - "x": 33 - } - ] - } - ] - }, - { - "description": "RetryableWriteError label is not added based on writeConcernError in pre-4.4 mongos response", - "runOnRequirements": [ - { - "minServerVersion": "4.2", - "maxServerVersion": "4.2.99", - "topologies": [ - "sharded" - ] - } - ], - "operations": [ - { - "name": "failPoint", - "object": "testRunner", - "arguments": { - "client": "client0", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "insert" - ], - "writeConcernError": { - "code": 91, - "errmsg": "Replication is being shut down" - } - } - } - } - }, - { - "name": "insertOne", - "object": "collection0", - "arguments": { - "document": { - "_id": 3, - "x": 33 - } - }, - "expectError": { - "errorLabelsOmit": [ - "RetryableWriteError" - ] - } - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "insert": "coll", - "documents": [ - { - "_id": 3, - "x": 33 - } - ] - }, - "commandName": "insert", - "databaseName": "retryable-writes-tests" - } - } - ] - } - ], - "outcome": [ - { - "collectionName": "coll", - "databaseName": "retryable-writes-tests", - "documents": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - }, - { - "_id": 3, - "x": 33 - } - ] - } - ] } ] }