@@ -370,27 +370,30 @@ def update_evalresults_db(
370
370
session = session ,
371
371
)
372
372
373
- def get_model_name_from_db (
374
- self ,
375
- model_id : str ,
376
- ) -> str :
373
+ def get_model_attribute_from_db (self , model_id : str , attribute : str ) -> str :
377
374
"""
378
- Retrieve model name from database using model_id .
375
+ Retrieve a specific attribute from a model in the database .
379
376
380
377
Args:
381
378
model_id: UUID string of the model
379
+ attribute: Name of the attribute to retrieve (e.g., 'name', 'weights_location')
382
380
383
381
Returns:
384
- str: Model name from database
382
+ str: Value of the requested attribute
385
383
386
384
Raises:
387
- RuntimeError: If model_id is not found in database or if database operation fails
385
+ RuntimeError: If model_id is not found in database or if attribute doesn't exist
386
+ ValueError: If model_id is not a valid UUID
388
387
"""
389
388
with self .session_scope () as session :
390
389
try :
391
390
model = session .get (Model , uuid .UUID (model_id ))
392
391
if model is None :
393
392
raise RuntimeError (f"Model with id { model_id } not found in database" )
394
- return model .name
393
+ if not hasattr (model , attribute ):
394
+ raise RuntimeError (f"Attribute '{ attribute } ' does not exist on Model" )
395
+ return getattr (model , attribute )
396
+ except ValueError as e :
397
+ raise ValueError (f"Invalid UUID format: { str (e )} " )
395
398
except Exception as e :
396
- raise RuntimeError (f"Database error in get_model_name_from_db : { str (e )} " )
399
+ raise RuntimeError (f"Database error in get_model_attribute_from_db : { str (e )} " )
0 commit comments