1
- from typing import Optional , Iterator , Iterable
1
+ from deprecation import deprecated
2
+ from typing import Optional , Union , Iterator , Iterable , Collection as TypingCollection
2
3
from uuid import UUID
4
+ from warnings import warn
3
5
4
6
from gemd .enumeration .base_enumeration import BaseEnumeration
5
7
@@ -188,14 +190,26 @@ class Ingestion(Resource['Ingestion']):
188
190
uid = properties .UUID ('ingestion_id' )
189
191
"""UUID: Unique uuid4 identifier of this ingestion."""
190
192
team_id = properties .Optional (properties .UUID , 'team_id' , default = None )
191
- project_id = properties .Optional (properties .UUID , 'project_id' , default = None )
193
+ _project_id = properties .Optional (properties .UUID , 'project_id' , default = None )
192
194
dataset_id = properties .UUID ('dataset_id' )
193
195
session = properties .Object (Session , 'session' , serializable = False )
194
196
raise_errors = properties .Optional (properties .Boolean (), 'raise_errors' , default = True )
195
197
198
+ @property
199
+ def project_id (self ) -> Optional [UUID ]:
200
+ """[DEPRECATED] The project ID associated with this ingest."""
201
+ return self ._project_id
202
+
203
+ @project_id .setter
204
+ @deprecated (deprecated_in = '3.9.0' , removed_in = '4.0.0' ,
205
+ details = "Use the project argument instead of setting the project_id attribute." )
206
+ def project_id (self , value : Optional [UUID ]):
207
+ self ._project_id = value
208
+
196
209
def build_objects (self ,
197
210
* ,
198
211
build_table : bool = False ,
212
+ project : Optional [Union ["Project" , UUID , str ]] = None , # noqa: F821
199
213
delete_dataset_contents : bool = False ,
200
214
delete_templates : bool = True ,
201
215
timeout : float = None ,
@@ -211,6 +225,8 @@ def build_objects(self,
211
225
----------
212
226
build_table: bool
213
227
Whether to build a table immediately after ingestion. Default : False
228
+ project: Optional[Project, UUID, or str]
229
+ Which project to use for table build if build_table is True.
214
230
delete_dataset_contents: bool
215
231
Whether to delete objects prior to generating new gemd objects. Default: False.
216
232
delete_templates: bool
@@ -231,6 +247,7 @@ def build_objects(self,
231
247
"""
232
248
try :
233
249
job = self .build_objects_async (build_table = build_table ,
250
+ project = project ,
234
251
delete_dataset_contents = delete_dataset_contents ,
235
252
delete_templates = delete_templates )
236
253
except IngestionException as e :
@@ -249,6 +266,7 @@ def build_objects(self,
249
266
def build_objects_async (self ,
250
267
* ,
251
268
build_table : bool = False ,
269
+ project : Optional [Union ["Project" , UUID , str ]] = None , # noqa: F821
252
270
delete_dataset_contents : bool = False ,
253
271
delete_templates : bool = True ) -> JobSubmissionResponse :
254
272
"""
@@ -258,6 +276,8 @@ def build_objects_async(self,
258
276
----------
259
277
build_table: bool
260
278
Whether to build a table immediately after ingestion. Default : False
279
+ project: Optional[Project, UUID, or str]
280
+ Which project to use for table build if build_table is True.
261
281
delete_dataset_contents: bool
262
282
Whether to delete objects prior to generating new gemd objects. Default: False.
263
283
delete_templates: bool
@@ -270,12 +290,35 @@ def build_objects_async(self,
270
290
The object for the submitted job
271
291
272
292
"""
293
+ from citrine .resources .project import Project
273
294
collection = IngestionCollection (team_id = self .team_id ,
274
295
dataset_id = self .dataset_id ,
275
296
session = self .session )
276
297
path = collection ._get_path (uid = self .uid , action = "gemd-objects-async" )
298
+
299
+ # Project resolution logic
300
+ if not build_table :
301
+ project_id = None
302
+ elif project is None :
303
+ if self .project_id is None :
304
+ raise ValueError ("Building a table requires a target project." )
305
+ else :
306
+ warn (
307
+ "Building a table with an implicit project is deprecated "
308
+ "and will be removed in v4. Please pass a project explicitly." ,
309
+ DeprecationWarning
310
+ )
311
+ project_id = self .project_id
312
+ elif isinstance (project , Project ):
313
+ project_id = project .uid
314
+ elif isinstance (project , UUID ):
315
+ project_id = project
316
+ else :
317
+ project_id = UUID (project )
318
+
277
319
params = {
278
320
"build_table" : build_table ,
321
+ "project_id" : project_id ,
279
322
"delete_dataset_contents" : delete_dataset_contents ,
280
323
"delete_templates" : delete_templates ,
281
324
}
@@ -358,20 +401,25 @@ def __init__(self, errors: Iterable[IngestionErrorTrace]):
358
401
def build_objects (self ,
359
402
* ,
360
403
build_table : bool = False ,
404
+ project : Optional [Union ["Project" , UUID , str ]] = None , # noqa: F821
361
405
delete_dataset_contents : bool = False ,
362
- delete_templates : bool = True ) -> IngestionStatus :
406
+ delete_templates : bool = True ,
407
+ timeout : float = None ,
408
+ polling_delay : Optional [float ] = None
409
+ ) -> IngestionStatus :
363
410
"""[ALPHA] Satisfy the required interface for a failed ingestion."""
364
411
return self .status ()
365
412
366
413
def build_objects_async (self ,
367
414
* ,
368
415
build_table : bool = False ,
416
+ project : Optional [Union ["Project" , UUID , str ]] = None , # noqa: F821
369
417
delete_dataset_contents : bool = False ,
370
418
delete_templates : bool = True ) -> JobSubmissionResponse :
371
419
"""[ALPHA] Satisfy the required interface for a failed ingestion."""
372
420
raise JobFailureError (
373
421
message = f"Errors: { [e .msg for e in self .errors ]} " ,
374
- job_id = None ,
422
+ job_id = UUID ( '0' * 32 ), # Nil UUID
375
423
failure_reasons = [e .msg for e in self .errors ]
376
424
)
377
425
@@ -384,7 +432,7 @@ def poll_for_job_completion(self,
384
432
"""[ALPHA] Satisfy the required interface for a failed ingestion."""
385
433
raise JobFailureError (
386
434
message = f"Errors: { [e .msg for e in self .errors ]} " ,
387
- job_id = None ,
435
+ job_id = UUID ( '0' * 32 ), # Nil UUID
388
436
failure_reasons = [e .msg for e in self .errors ]
389
437
)
390
438
@@ -401,8 +449,8 @@ def status(self) -> IngestionStatus:
401
449
if self .raise_errors :
402
450
raise JobFailureError (
403
451
message = f"Ingestion creation failed: { self .errors } " ,
404
- job_id = None ,
405
- failure_reasons = self .errors
452
+ job_id = UUID ( '0' * 32 ), # Nil UUID
453
+ failure_reasons = [ str ( x ) for x in self .errors ]
406
454
)
407
455
else :
408
456
return IngestionStatus .build ({
@@ -461,7 +509,7 @@ def _path_template(self):
461
509
return f'projects/{ self .project_id } /ingestions'
462
510
463
511
def build_from_file_links (self ,
464
- file_links : Iterable [FileLink ],
512
+ file_links : TypingCollection [FileLink ],
465
513
* ,
466
514
raise_errors : bool = True ) -> Ingestion :
467
515
"""
0 commit comments