|
35 | 35 | InvocationCancelledError, |
36 | 36 | invocation_logger, |
37 | 37 | ) |
38 | | -from ..outputs.blob import BlobIOContextDep |
| 38 | +from ..outputs.blob import BlobIOContextDep, blobdata_to_url_ctx |
39 | 39 |
|
40 | 40 | if TYPE_CHECKING: |
41 | 41 | # We only need these imports for type hints, so this avoids circular imports. |
|
46 | 46 | """The API route used to list `.Invocation` objects.""" |
47 | 47 |
|
48 | 48 |
|
| 49 | +class NoBlobManagerError(RuntimeError): |
| 50 | + """Raised if an API route accesses Invocation outputs without a BlobIOContextDep. |
| 51 | +
|
| 52 | + Any access to an invocation output must have BlobIOContextDep as a dependency, as |
| 53 | + the output may be a blob, and the blob needs this context to resolve its URL. |
| 54 | + """ |
| 55 | + |
| 56 | + |
49 | 57 | class Invocation(Thread): |
50 | 58 | """A Thread subclass that retains output values and tracks progress. |
51 | 59 |
|
@@ -123,7 +131,23 @@ def id(self) -> uuid.UUID: |
123 | 131 |
|
124 | 132 | @property |
125 | 133 | def output(self) -> Any: |
126 | | - """Return value of the Action. If the Action is still running, returns None.""" |
| 134 | + """Return value of the Action. If the Action is still running, returns None. |
| 135 | +
|
| 136 | + :raise NoBlobManagerError: If this is called in a context where the blob |
| 137 | + manager context variables are not available. This stops errors being raised |
| 138 | + later once the blob is returned and tries to serialise. If the errors |
| 139 | + happen during serialisation the stack-trace will not clearly identify |
| 140 | + the route with the missing dependency. |
| 141 | + """ |
| 142 | + try: |
| 143 | + blobdata_to_url_ctx.get() |
| 144 | + except LookupError as e: |
| 145 | + raise NoBlobManagerError( |
| 146 | + "An invocation output has been requested from a api route that " |
| 147 | + "doesn't have a BlobIOContextDep dependency. This dependency is needed " |
| 148 | + " for blobs to identify their url." |
| 149 | + ) from e |
| 150 | + |
127 | 151 | with self._status_lock: |
128 | 152 | return self._return_value |
129 | 153 |
|
|
0 commit comments