@@ -2385,9 +2385,8 @@ class SlurmComputeResource(_BaseSlurmComputeResource):
23852385
23862386 def __init__ (self , instance_type = None , ** kwargs ):
23872387 super ().__init__ (** kwargs )
2388- _instance_type = instance_type if instance_type else self ._instance_type_from_capacity_reservation ()
2389- self .instance_type = Resource .init_param (_instance_type )
23902388 self .__instance_type_info = None
2389+ self ._instance_type = Resource .init_param (instance_type )
23912390
23922391 def is_flexible (self ):
23932392 """Return False because the ComputeResource can not contain multiple instance types."""
@@ -2398,6 +2397,14 @@ def instance_types(self) -> List[str]:
23982397 """List of instance types under this compute resource."""
23992398 return [self .instance_type ]
24002399
2400+ @property
2401+ # Do not invoke in update path
2402+ def instance_type (self ):
2403+ """Instance type of this compute resource."""
2404+ if not self ._instance_type :
2405+ self ._instance_type = Resource .init_param (self ._instance_type_from_capacity_reservation ())
2406+ return self ._instance_type
2407+
24012408 def _register_validators (self , context : ValidatorContext = None ):
24022409 super ()._register_validators (context )
24032410 self ._register_validator (
@@ -2446,13 +2453,9 @@ def _instance_type_from_capacity_reservation(self):
24462453 self .capacity_reservation_target .capacity_reservation_id if self .capacity_reservation_target else None
24472454 )
24482455 if capacity_reservation_id :
2449- try :
2450- capacity_reservations = AWSApi .instance ().ec2 .describe_capacity_reservations ([capacity_reservation_id ])
2451- if capacity_reservations :
2452- instance_type = capacity_reservations [0 ].instance_type ()
2453- except AWSClientError :
2454- # In case the CR has expired and we are unable to retrieve the instance type
2455- instance_type = None
2456+ capacity_reservations = AWSApi .instance ().ec2 .describe_capacity_reservations ([capacity_reservation_id ])
2457+ if capacity_reservations :
2458+ instance_type = capacity_reservations [0 ].instance_type ()
24562459 return instance_type
24572460
24582461
0 commit comments