I cannot reproduce this error with the info you’ve provided. The code example works as expected on 4.4.4 for me:
>>> client = MongoClient(w='majority')
>>> client.t.t.insert_one({}) # Create collection
<pymongo.results.InsertOneResult object at 0x7fe853a3ee00>
>>> with client.start_session() as s, s.start_transaction():
... client.t.t.insert_one({}, session=s)
...
<pymongo.results.InsertOneResult object at 0x7fe85668e6c0>
Could you please provide the full python, pymongo, and server version info? Like this:
>>> import sys
>>> sys.version
'3.9.0 (v3.9.0:9cf6752276, Oct 5 2020, 11:29:23) \n[Clang 6.0 (clang-600.0.57)]'
>>> import pymongo
>>> pymongo.version
'3.11.3'
>>> client.server_info()
{'version': '4.4.4', 'gitVersion': '8db30a63db1a9d84bdcad0c83369623f708e0397', 'modules': ['enterprise'], 'allocator': 'system', 'javascriptEngine': 'mozjs', 'sysInfo': 'deprecated', 'versionArray': [4, 4, 4, 0], 'openssl': {'running': 'Apple Secure Transport'}, ..., 'bits': 64, 'debug': False, 'maxBsonObjectSize': 16777216, 'storageEngines': ['biggie', 'devnull', 'ephemeralForTest', 'inMemory', 'queryable_wt', 'wiredTiger'], 'ok': 1.0, '$clusterTime': {'clusterTime': Timestamp(1614705437, 1), 'signature': {'hash': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'keyId': 0}}, 'operationTime': Timestamp(1614705437, 1)}
Please also include the full exception traceback. For example, I can force the server to return this error (mis)using the low-level Database.command API like this:
>>> with client.start_session() as s, s.start_transaction():
... client.t.command('insert', 't', documents=[{}], writeConcern={'w':1}, session=s)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/Users/shane/git/mongo-python-driver/pymongo/database.py", line 738, in command
return self._command(sock_info, command, slave_ok, value,
File "/Users/shane/git/mongo-python-driver/pymongo/database.py", line 626, in _command
return sock_info.command(
File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", line 683, in command
return command(self, dbname, spec, slave_ok,
File "/Users/shane/git/mongo-python-driver/pymongo/network.py", line 159, in command
helpers._check_command_response(
File "/Users/shane/git/mongo-python-driver/pymongo/helpers.py", line 164, in _check_command_response
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: writeConcern is not allowed within a multi-statement transaction, full error: {'operationTime': Timestamp(1614706228, 1), 'ok': 0.0, 'errmsg': 'writeConcern is not allowed within a multi-statement transaction', 'code': 72, 'codeName': 'InvalidOptions', '$clusterTime': {'clusterTime': Timestamp(1614706228, 1), 'signature': {'hash': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'keyId': 0}}}