Skip to content

PYTHON-5129 - Fix async transaction docstrings #2138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pymongo/asynchronous/client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

.. code-block:: python

with client.start_session(causal_consistency=True) as session:
async with client.start_session(causal_consistency=True) as session:
collection = client.db.collection
await collection.update_one({"_id": 1}, {"$set": {"x": 10}}, session=session)
secondary_c = collection.with_options(read_preference=ReadPreference.SECONDARY)
Expand Down Expand Up @@ -53,16 +53,16 @@

orders = client.db.orders
inventory = client.db.inventory
with client.start_session() as session:
async with session.start_transaction():
async with client.start_session() as session:
async with await session.start_transaction():
await orders.insert_one({"sku": "abc123", "qty": 100}, session=session)
await inventory.update_one(
{"sku": "abc123", "qty": {"$gte": 100}},
{"$inc": {"qty": -100}},
session=session,
)

Upon normal completion of ``async with session.start_transaction()`` block, the
Upon normal completion of ``async with await session.start_transaction()`` block, the
transaction automatically calls :meth:`AsyncClientSession.commit_transaction`.
If the block exits with an exception, the transaction automatically calls
:meth:`AsyncClientSession.abort_transaction`.
Expand Down Expand Up @@ -113,7 +113,7 @@
.. code-block:: python

# Each read using this session reads data from the same point in time.
with client.start_session(snapshot=True) as session:
async with client.start_session(snapshot=True) as session:
order = await orders.find_one({"sku": "abc123"}, session=session)
inventory = await inventory.find_one({"sku": "abc123"}, session=session)

Expand Down Expand Up @@ -619,7 +619,7 @@ async def callback(session):
await inventory.update_one({"sku": "abc123", "qty": {"$gte": 100}},
{"$inc": {"qty": -100}}, session=session)

with client.start_session() as session:
async with client.start_session() as session:
await session.with_transaction(callback)

To pass arbitrary arguments to the ``callback``, wrap your callable
Expand All @@ -628,7 +628,7 @@ async def callback(session):
async def callback(session, custom_arg, custom_kwarg=None):
# Transaction operations...

with client.start_session() as session:
async with client.start_session() as session:
await session.with_transaction(
lambda s: callback(s, "custom_arg", custom_kwarg=1))

Expand Down
Loading