Get the currently active TortoiseContext, raising if none is active. Returns: The current TortoiseContext. Raises: RuntimeError: If no TortoiseContext is currently active.
()
| 97 | |
| 98 | |
| 99 | def require_context() -> TortoiseContext: |
| 100 | """ |
| 101 | Get the currently active TortoiseContext, raising if none is active. |
| 102 | |
| 103 | Returns: |
| 104 | The current TortoiseContext. |
| 105 | |
| 106 | Raises: |
| 107 | RuntimeError: If no TortoiseContext is currently active. |
| 108 | """ |
| 109 | ctx = get_current_context() |
| 110 | if ctx is None: |
| 111 | raise RuntimeError( |
| 112 | "No TortoiseContext is currently active. " |
| 113 | "Use 'async with TortoiseContext() as ctx:' to create one, " |
| 114 | "or call Tortoise.init() for global state." |
| 115 | ) |
| 116 | return ctx |
| 117 | |
| 118 | |
| 119 | class TortoiseContext: |
searching dependent graphs…