Fix an issue listing collections

This commit is contained in:
Cyber MacGeddon 2025-09-19 11:13:22 +01:00
parent bada1f53eb
commit 6ba56a2b42
2 changed files with 12 additions and 3 deletions

View file

@ -27,6 +27,14 @@ class Collection:
object = self.request(input) object = self.request(input)
try: 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 [ return [
CollectionMetadata( CollectionMetadata(
user = v["user"], user = v["user"],
@ -37,7 +45,7 @@ class Collection:
created_at = v["created_at"], created_at = v["created_at"],
updated_at = v["updated_at"] updated_at = v["updated_at"]
) )
for v in object["collections"] for v in collections
] ]
except Exception as e: except Exception as e:
logger.error("Failed to parse collection list response", exc_info=True) logger.error("Failed to parse collection list response", exc_info=True)

View file

@ -17,8 +17,9 @@ def list_collections(url, user, tag_filter):
collections = api.list_collections(user=user, tag_filter=tag_filter) collections = api.list_collections(user=user, tag_filter=tag_filter)
if len(collections) == 0: # Handle None or empty collections
print("No collections.") if not collections or len(collections) == 0:
print("No collections found.")
return return
table = [] table = []