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
()
| 53 | |
| 54 | |
| 55 | def 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 | |
| 71 | def set_global_context(ctx: TortoiseContext) -> None: |
searching dependent graphs…