1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-22 22:03:54 +03:00

Fix model detail retrieval error handling

This commit is contained in:
Adolfo Gómez García 2024-07-15 18:21:25 +02:00
parent c1c922b87b
commit 773c3b5b50
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
2 changed files with 8 additions and 8 deletions

View File

@ -192,7 +192,7 @@ class ModelHandler(BaseModelHandler):
def process_detail(self) -> typing.Any:
logger.debug('Processing detail %s for with params %s', self._path, self._params)
try:
item: models.Model = self.model.objects.filter(uuid__iexact=self._args[0])[0]
item: models.Model = self.model.objects.get(uuid__iexact=self._args[0])
# If we do not have access to parent to, at least, read...
if self._operation in ('put', 'post', 'delete'):
@ -219,8 +219,8 @@ class ModelHandler(BaseModelHandler):
method = getattr(detail_handler, self._operation)
return method()
except IndexError as e:
raise self.invalid_item_response() from e
except self.model.DoesNotExist:
raise self.invalid_item_response()
except (KeyError, AttributeError) as e:
raise self.invalid_method_response() from e
except exceptions.rest.HandlerError:

View File

@ -743,7 +743,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
Get service info from user service
"""
if user_service_id[0] == 'M': # Meta pool
return self.get_meta_service_info(user, src_ip, os, user_service_id[1:], transport_id or '')
return self.get_meta_service_info(user, src_ip, os, user_service_id[1:], transport_id or 'meta')
user_service = self.locate_user_service(user, user_service_id, create=True)
@ -957,16 +957,16 @@ class UserServiceManager(metaclass=singleton.Singleton):
# Remove "full" pools (100%) from result and pools in maintenance mode, not ready pools, etc...
sortedPools = sorted(sortPools, key=operator.itemgetter(0)) # sort by priority (first element)
pools: list[ServicePool] = []
poolsFull: list[ServicePool] = []
pool_full: list[ServicePool] = []
for p in sortedPools:
if not p[1].is_usable():
continue
if p[1].usage().percent == 100:
poolsFull.append(p[1])
pool_full.append(p[1])
else:
pools.append(p[1])
logger.debug('Pools: %s/%s', pools, poolsFull)
logger.debug('Pools: %s/%s', pools, pool_full)
usable: typing.Optional[tuple[ServicePool, Transport]] = None
# Now, Lets find first if there is one assigned in ANY pool
@ -998,7 +998,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
try:
# Already assigned should look for in all usable pools, not only "non-full" ones
alreadyAssigned: UserService = UserService.objects.filter(
deployed_service__in=pools + poolsFull,
deployed_service__in=pools + pool_full,
state__in=State.VALID_STATES,
user=user,
cache_level=0,