MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / inner

Function inner

pymongo/asynchronous/helpers.py:47–74  ·  view source on GitHub ↗
(*args: Any, **kwargs: Any)

Source from the content-addressed store, hash-verified

45def _handle_reauth(func: F) -> F:
46 @functools.wraps(func)
47 async def inner(*args: Any, **kwargs: Any) -> Any:
48 no_reauth = kwargs.pop("no_reauth", False)
49 from pymongo.asynchronous.pool import AsyncConnection
50 from pymongo.message import _BulkWriteContext
51
52 try:
53 return await func(*args, **kwargs)
54 except OperationFailure as exc:
55 if no_reauth:
56 raise
57 if exc.code == _REAUTHENTICATION_REQUIRED_CODE:
58 # Look for an argument that either is a AsyncConnection
59 # or has a connection attribute, so we can trigger
60 # a reauth.
61 conn = None
62 for arg in args:
63 if isinstance(arg, AsyncConnection):
64 conn = arg
65 break
66 if isinstance(arg, _BulkWriteContext):
67 conn = arg.conn # type: ignore[assignment]
68 break
69 if conn:
70 await conn.authenticate(reauthenticate=True)
71 else:
72 raise
73 return await func(*args, **kwargs)
74 raise
75
76 return cast(F, inner)
77

Callers

nothing calls this directly

Calls 2

popMethod · 0.45
authenticateMethod · 0.45

Tested by

no test coverage detected