Return the active :class:`Workspace` for *identity_id*. For local/Azure: uses WorkspaceManager with lazy creation. For ephemeral: creates a scratch workspace and materializes table data from ``_workspace_tables`` in the request body. The frontend (IndexedDB) owns all data and
(identity_id: str)
| 127 | |
| 128 | |
| 129 | def get_workspace(identity_id: str) -> Workspace: |
| 130 | """ |
| 131 | Return the active :class:`Workspace` for *identity_id*. |
| 132 | |
| 133 | For local/Azure: uses WorkspaceManager with lazy creation. |
| 134 | For ephemeral: creates a scratch workspace and materializes table data |
| 135 | from ``_workspace_tables`` in the request body. The frontend (IndexedDB) |
| 136 | owns all data and sends it with every request; the backend writes it to |
| 137 | temp parquet files so agents/DuckDB can read normally. |
| 138 | """ |
| 139 | ws_id = get_active_workspace_id() |
| 140 | if not ws_id: |
| 141 | raise ValueError("No active workspace. X-Workspace-Id header is required.") |
| 142 | |
| 143 | backend = _get_backend() |
| 144 | |
| 145 | if backend == "ephemeral": |
| 146 | from data_formulator.datalake.ephemeral_workspace import construct_scratch_workspace |
| 147 | |
| 148 | # Extract workspace tables from the request body |
| 149 | workspace_tables = [] |
| 150 | from flask import request |
| 151 | if request.is_json: |
| 152 | data = request.get_json(silent=True) or {} |
| 153 | workspace_tables = data.get("_workspace_tables") or [] |
| 154 | |
| 155 | return construct_scratch_workspace(identity_id, ws_id, workspace_tables) |
| 156 | |
| 157 | mgr = get_workspace_manager(identity_id) |
| 158 | |
| 159 | # Lazy creation: frontend generates the ID, backend creates on first use |
| 160 | if not mgr.workspace_exists(ws_id): |
| 161 | mgr.create_workspace(ws_id) |
| 162 | |
| 163 | return mgr.open_workspace(ws_id, identity_id) |
no test coverage detected