From 6ba56a2b4220855aefc4e48fa31b239feadace43 Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Fri, 19 Sep 2025 11:13:22 +0100 Subject: [PATCH] Fix an issue listing collections --- trustgraph-base/trustgraph/api/collection.py | 10 +++++++++- trustgraph-cli/trustgraph/cli/list_collections.py | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/trustgraph-base/trustgraph/api/collection.py b/trustgraph-base/trustgraph/api/collection.py index 9a826899..0e1abeaf 100644 --- a/trustgraph-base/trustgraph/api/collection.py +++ b/trustgraph-base/trustgraph/api/collection.py @@ -27,6 +27,14 @@ class Collection: object = self.request(input) try: + # Handle case where collections might be None or missing + if object is None or "collections" not in object: + return [] + + collections = object.get("collections", []) + if collections is None: + return [] + return [ CollectionMetadata( user = v["user"], @@ -37,7 +45,7 @@ class Collection: created_at = v["created_at"], updated_at = v["updated_at"] ) - for v in object["collections"] + for v in collections ] except Exception as e: logger.error("Failed to parse collection list response", exc_info=True) diff --git a/trustgraph-cli/trustgraph/cli/list_collections.py b/trustgraph-cli/trustgraph/cli/list_collections.py index 8429b0cb..56929e93 100644 --- a/trustgraph-cli/trustgraph/cli/list_collections.py +++ b/trustgraph-cli/trustgraph/cli/list_collections.py @@ -17,8 +17,9 @@ def list_collections(url, user, tag_filter): collections = api.list_collections(user=user, tag_filter=tag_filter) - if len(collections) == 0: - print("No collections.") + # Handle None or empty collections + if not collections or len(collections) == 0: + print("No collections found.") return table = []