From 2095013e6ffdc06d1bf4325df6375828029c16a9 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 16 Jul 2025 16:35:04 -0500 Subject: [PATCH 1/4] PYTHON-4019 Infinite loop in generic transactional provider due to dup keys --- pymongo/asynchronous/client_session.py | 5 +++++ pymongo/synchronous/client_session.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/pymongo/asynchronous/client_session.py b/pymongo/asynchronous/client_session.py index b808684dd4..aca99f562d 100644 --- a/pymongo/asynchronous/client_session.py +++ b/pymongo/asynchronous/client_session.py @@ -660,6 +660,11 @@ async def callback(session, custom_arg, custom_kwarg=None): ``with_transaction`` starts a new transaction and re-executes the ``callback``. + The ``callback`` MUST NOT silently handle command errors + without allowing such errors to propagate. Command errors may abort the + transaction on the server, and an attempt to commit the transaction will + be rejected with a ``NoSuchTransaction`` error. + When :meth:`~AsyncClientSession.commit_transaction` raises an exception with the ``"UnknownTransactionCommitResult"`` error label, ``with_transaction`` retries the commit until the result of the diff --git a/pymongo/synchronous/client_session.py b/pymongo/synchronous/client_session.py index aaf2d7574f..fbd77fa022 100644 --- a/pymongo/synchronous/client_session.py +++ b/pymongo/synchronous/client_session.py @@ -659,6 +659,11 @@ def callback(session, custom_arg, custom_kwarg=None): ``with_transaction`` starts a new transaction and re-executes the ``callback``. + The ``callback`` MUST NOT silently handle command errors + without allowing such errors to propagate. Command errors may abort the + transaction on the server, and an attempt to commit the transaction will + be rejected with a ``NoSuchTransaction`` error. + When :meth:`~ClientSession.commit_transaction` raises an exception with the ``"UnknownTransactionCommitResult"`` error label, ``with_transaction`` retries the commit until the result of the From e999ed27716f6b5ceb8e0cf5c9e536bed9f67ad0 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 16 Jul 2025 19:35:48 -0500 Subject: [PATCH 2/4] address review --- pymongo/asynchronous/client_session.py | 6 +++++- pymongo/synchronous/client_session.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pymongo/asynchronous/client_session.py b/pymongo/asynchronous/client_session.py index aca99f562d..13ab6fe4af 100644 --- a/pymongo/asynchronous/client_session.py +++ b/pymongo/asynchronous/client_session.py @@ -663,7 +663,8 @@ async def callback(session, custom_arg, custom_kwarg=None): The ``callback`` MUST NOT silently handle command errors without allowing such errors to propagate. Command errors may abort the transaction on the server, and an attempt to commit the transaction will - be rejected with a ``NoSuchTransaction`` error. + be rejected with a ``NoSuchTransaction`` error. For more information see + the `transactions specification`_. When :meth:`~AsyncClientSession.commit_transaction` raises an exception with the ``"UnknownTransactionCommitResult"`` error label, @@ -694,6 +695,9 @@ async def callback(session, custom_arg, custom_kwarg=None): :return: The return value of the ``callback``. .. versionadded:: 3.9 + + .. _tranactions specification: + https://github.com/mongodb/specifications/blob/master/source/transactions-convenient-api/transactions-convenient-api.md#handling-errors-inside-the-callback """ start_time = time.monotonic() while True: diff --git a/pymongo/synchronous/client_session.py b/pymongo/synchronous/client_session.py index fbd77fa022..b99a78e15d 100644 --- a/pymongo/synchronous/client_session.py +++ b/pymongo/synchronous/client_session.py @@ -662,7 +662,8 @@ def callback(session, custom_arg, custom_kwarg=None): The ``callback`` MUST NOT silently handle command errors without allowing such errors to propagate. Command errors may abort the transaction on the server, and an attempt to commit the transaction will - be rejected with a ``NoSuchTransaction`` error. + be rejected with a ``NoSuchTransaction`` error. For more information see + the `transactions specification`_. When :meth:`~ClientSession.commit_transaction` raises an exception with the ``"UnknownTransactionCommitResult"`` error label, @@ -693,6 +694,9 @@ def callback(session, custom_arg, custom_kwarg=None): :return: The return value of the ``callback``. .. versionadded:: 3.9 + + .. _tranactions specification: + https://github.com/mongodb/specifications/blob/master/source/transactions-convenient-api/transactions-convenient-api.md#handling-errors-inside-the-callback """ start_time = time.monotonic() while True: From 079499298fb9eecfb3a626cb645f4f3e42a665d2 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 17 Jul 2025 07:13:22 -0500 Subject: [PATCH 3/4] fix typo --- pymongo/asynchronous/client_session.py | 2 +- pymongo/synchronous/client_session.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pymongo/asynchronous/client_session.py b/pymongo/asynchronous/client_session.py index 13ab6fe4af..1225445710 100644 --- a/pymongo/asynchronous/client_session.py +++ b/pymongo/asynchronous/client_session.py @@ -696,7 +696,7 @@ async def callback(session, custom_arg, custom_kwarg=None): .. versionadded:: 3.9 - .. _tranactions specification: + .. _transactions specification: https://github.com/mongodb/specifications/blob/master/source/transactions-convenient-api/transactions-convenient-api.md#handling-errors-inside-the-callback """ start_time = time.monotonic() diff --git a/pymongo/synchronous/client_session.py b/pymongo/synchronous/client_session.py index b99a78e15d..8d5bf7697b 100644 --- a/pymongo/synchronous/client_session.py +++ b/pymongo/synchronous/client_session.py @@ -695,7 +695,7 @@ def callback(session, custom_arg, custom_kwarg=None): .. versionadded:: 3.9 - .. _tranactions specification: + .. _transactions specification: https://github.com/mongodb/specifications/blob/master/source/transactions-convenient-api/transactions-convenient-api.md#handling-errors-inside-the-callback """ start_time = time.monotonic() From 73889861c03b6779f719c7d4f14f611d35884db5 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 17 Jul 2025 07:20:21 -0500 Subject: [PATCH 4/4] add linkcheck ignore --- doc/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/conf.py b/doc/conf.py index a9711d259f..8a7f418609 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -86,6 +86,7 @@ # sourceforge.net is giving a 403 error, but is still accessible from the browser. linkcheck_ignore = [ "https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-monitoring.md#requesting-an-immediate-check", + "https://github.com/mongodb/specifications/blob/master/source/transactions-convenient-api/transactions-convenient-api.md#handling-errors-inside-the-callback", "https://github.com/mongodb/libmongocrypt/blob/master/bindings/python/README.rst#installing-from-source", r"https://wiki.centos.org/[\w/]*", r"https://sourceforge.net/",