From 2fd1728c421e19ee866fe984d02a3dac30a4b462 Mon Sep 17 00:00:00 2001 From: 1yam Date: Thu, 27 Nov 2025 11:57:55 +0100 Subject: [PATCH] Fix: CrnList is no longer a Dict, type check making failed the match of the crn-url with crn-hash --- src/aleph/sdk/client/services/instance.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/aleph/sdk/client/services/instance.py b/src/aleph/sdk/client/services/instance.py index 034ee4b9..9a2dcf20 100644 --- a/src/aleph/sdk/client/services/instance.py +++ b/src/aleph/sdk/client/services/instance.py @@ -4,6 +4,7 @@ from aleph_message.models import InstanceMessage, ItemHash, MessageType, PaymentType from aleph_message.status import MessageStatus +from aleph.sdk.client.services.crn import CrnList from aleph.sdk.query.filters import MessageFilter from aleph.sdk.query.responses import MessagesResponse @@ -47,7 +48,7 @@ async def get_name_of_executable(self, item_hash: ItemHash) -> Optional[str]: return None async def get_instance_allocation_info( - self, msg: InstanceMessage, crn_list: dict + self, msg: InstanceMessage, crn_list: CrnList ) -> Tuple[InstanceMessage, Union[InstanceManual, InstanceWithScheduler]]: vm_hash = msg.item_hash payment_type = safe_getattr(msg, "content.payment.type.value") @@ -62,12 +63,8 @@ async def get_instance_allocation_info( info = InstanceWithScheduler(source="scheduler", allocations=alloc) else: crn_hash = safe_getattr(msg, "content.requirements.node.node_hash") - if isinstance(crn_list, list): - node = next((n for n in crn_list if n.get("hash") == crn_hash), None) - url = sanitize_url(node.get("address")) if node else "" - else: - node = crn_list.get(crn_hash) - url = sanitize_url(node.get("address")) if node else "" + node = crn_list.find_crn_by_hash(crn_hash) + url = sanitize_url(node.address) if node else "" info = InstanceManual(source="manual", crn_url=url) return msg, info @@ -84,8 +81,7 @@ async def get_instances(self, address: str) -> List[InstanceMessage]: return resp.messages async def get_instances_allocations(self, messages_list, only_processed=True): - crn_list_response = await self._client.crn.get_crns_list() - crn_list = crn_list_response.get("crns", {}) + crn_list = await self._client.crn.get_crns_list(only_active=False) tasks = [] for msg in messages_list: