MCPcopy
hub / github.com/tortoise/tortoise-orm / get_current_context

Function get_current_context

tortoise/context.py:55–68  ·  view source on GitHub ↗

Get the currently active TortoiseContext, or None if no context is active. Checks the contextvar first (for proper isolation), then falls back to the global context if one was set via _enable_global_fallback. Returns: The current TortoiseContext if one is active, None othe

()

Source from the content-addressed store, hash-verified

53
54
55def get_current_context() -> TortoiseContext | None:
56 """
57 Get the currently active TortoiseContext, or None if no context is active.
58
59 Checks the contextvar first (for proper isolation), then falls back to
60 the global context if one was set via _enable_global_fallback.
61
62 Returns:
63 The current TortoiseContext if one is active, None otherwise.
64 """
65 ctx = _current_context.get()
66 if ctx is not None:
67 return ctx
68 return _global_context
69
70
71def set_global_context(ctx: TortoiseContext) -> None:

Calls 1

getMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…