@@ -114,6 +114,8 @@ def prepare_history_download(self, request: GenerateHistoryDownload):
114
114
include_hidden = request .include_hidden
115
115
include_deleted = request .include_deleted
116
116
export_metadata = self .set_history_export_request_metadata (request )
117
+
118
+ exception_exporting_history : Optional [Exception ] = None
117
119
try :
118
120
with storage_context (
119
121
request .short_term_storage_request_id , self ._short_term_storage_monitor
@@ -122,12 +124,16 @@ def prepare_history_download(self, request: GenerateHistoryDownload):
122
124
short_term_storage_target .path
123
125
) as export_store :
124
126
export_store .export_history (history , include_hidden = include_hidden , include_deleted = include_deleted )
125
- self .set_history_export_result_metadata (request .export_association_id , export_metadata , success = True )
126
- except Exception as e :
127
+ except Exception as exception :
128
+ exception_exporting_history = exception
129
+ raise
130
+ finally :
127
131
self .set_history_export_result_metadata (
128
- request .export_association_id , export_metadata , success = False , error = str (e )
132
+ request .export_association_id ,
133
+ export_metadata ,
134
+ success = not bool (exception_exporting_history ),
135
+ error = str (exception_exporting_history ) if exception_exporting_history else None ,
129
136
)
130
- raise
131
137
132
138
def prepare_history_content_download (self , request : GenerateHistoryContentDownload ):
133
139
model_store_format = request .model_store_format
@@ -140,11 +146,13 @@ def prepare_history_content_download(self, request: GenerateHistoryContentDownlo
140
146
) as export_store :
141
147
if request .content_type == HistoryContentType .dataset :
142
148
hda = self ._sa_session .get (model .HistoryDatasetAssociation , request .content_id )
143
- export_store .add_dataset (hda )
149
+ export_store .add_dataset (hda ) # type: ignore[arg-type]
144
150
else :
145
151
hdca = self ._sa_session .get (model .HistoryDatasetCollectionAssociation , request .content_id )
146
152
export_store .export_collection (
147
- hdca , include_hidden = request .include_hidden , include_deleted = request .include_deleted
153
+ hdca , # type: ignore[arg-type]
154
+ include_hidden = request .include_hidden ,
155
+ include_deleted = request .include_deleted ,
148
156
)
149
157
150
158
def prepare_invocation_download (self , request : GenerateInvocationDownload ):
@@ -161,7 +169,9 @@ def prepare_invocation_download(self, request: GenerateInvocationDownload):
161
169
)(short_term_storage_target .path ) as export_store :
162
170
invocation = self ._sa_session .get (model .WorkflowInvocation , request .invocation_id )
163
171
export_store .export_workflow_invocation (
164
- invocation , include_hidden = request .include_hidden , include_deleted = request .include_deleted
172
+ invocation , # type: ignore[arg-type]
173
+ include_hidden = request .include_hidden ,
174
+ include_deleted = request .include_deleted ,
165
175
)
166
176
167
177
def write_invocation_to (self , request : WriteInvocationTo ):
@@ -178,7 +188,9 @@ def write_invocation_to(self, request: WriteInvocationTo):
178
188
)(target_uri ) as export_store :
179
189
invocation = self ._sa_session .get (model .WorkflowInvocation , request .invocation_id )
180
190
export_store .export_workflow_invocation (
181
- invocation , include_hidden = request .include_hidden , include_deleted = request .include_deleted
191
+ invocation , # type: ignore[arg-type]
192
+ include_hidden = request .include_hidden ,
193
+ include_deleted = request .include_deleted ,
182
194
)
183
195
184
196
def _bco_export_options (self , request : BcoGenerationTaskParametersMixin ):
@@ -202,33 +214,44 @@ def write_history_content_to(self, request: WriteHistoryContentTo):
202
214
)(target_uri ) as export_store :
203
215
if request .content_type == HistoryContentType .dataset :
204
216
hda = self ._sa_session .get (model .HistoryDatasetAssociation , request .content_id )
205
- export_store .add_dataset (hda )
217
+ export_store .add_dataset (hda ) # type: ignore[arg-type]
206
218
else :
207
219
hdca = self ._sa_session .get (model .HistoryDatasetCollectionAssociation , request .content_id )
208
220
export_store .export_collection (
209
- hdca , include_hidden = request .include_hidden , include_deleted = request .include_deleted
221
+ hdca , # type: ignore[arg-type]
222
+ include_hidden = request .include_hidden ,
223
+ include_deleted = request .include_deleted ,
210
224
)
211
225
212
226
def write_history_to (self , request : WriteHistoryTo ):
213
227
model_store_format = request .model_store_format
214
228
export_files = "symlink" if request .include_files else None
215
- target_uri = request .target_uri
216
229
user_context = self ._build_user_context (request .user .user_id )
217
230
export_metadata = self .set_history_export_request_metadata (request )
231
+
232
+ exception_exporting_history : Optional [Exception ] = None
233
+ uri : Optional [str ] = None
218
234
try :
219
- with model .store .get_export_store_factory (
235
+ export_store = model .store .get_export_store_factory (
220
236
self ._app , model_store_format , export_files = export_files , user_context = user_context
221
- )(target_uri ) as export_store :
237
+ )(request .target_uri )
238
+ with export_store :
222
239
history = self ._history_manager .by_id (request .history_id )
223
240
export_store .export_history (
224
241
history , include_hidden = request .include_hidden , include_deleted = request .include_deleted
225
242
)
226
- self .set_history_export_result_metadata (request .export_association_id , export_metadata , success = True )
227
- except Exception as e :
243
+ uri = str (export_store .file_source_uri ) if export_store .file_source_uri else request .target_uri
244
+ except Exception as exception :
245
+ exception_exporting_history = exception
246
+ raise
247
+ finally :
228
248
self .set_history_export_result_metadata (
229
- request .export_association_id , export_metadata , success = False , error = str (e )
249
+ request .export_association_id ,
250
+ export_metadata ,
251
+ success = not bool (exception_exporting_history ),
252
+ uri = uri ,
253
+ error = str (exception_exporting_history ) if exception_exporting_history else None ,
230
254
)
231
- raise
232
255
233
256
def set_history_export_request_metadata (
234
257
self , request : Union [WriteHistoryTo , GenerateHistoryDownload ]
@@ -257,10 +280,11 @@ def set_history_export_result_metadata(
257
280
export_association_id : Optional [int ],
258
281
export_metadata : Optional [ExportObjectMetadata ],
259
282
success : bool ,
283
+ uri : Optional [str ] = None ,
260
284
error : Optional [str ] = None ,
261
285
):
262
286
if export_association_id is not None and export_metadata is not None :
263
- export_metadata .result_data = ExportObjectResultMetadata (success = success , error = error )
287
+ export_metadata .result_data = ExportObjectResultMetadata (success = success , uri = uri , error = error )
264
288
self ._export_tracker .set_export_association_metadata (export_association_id , export_metadata )
265
289
266
290
def import_model_store (self , request : ImportModelStoreTaskRequest ):
0 commit comments