Fix KeyError on keyword/tag objects without 'name' field

Tandoor recipe list API may return keyword objects without a 'name'
key, causing KeyError('name'). Use .get() with filtering across all
tag/keyword list comprehensions in both Mealie and Tandoor clients.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 08:36:13 +01:00
parent 19cbd505d4
commit 8f4f7f245b
2 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -126,7 +126,7 @@ class MealieClient:
"id": item["slug"],
"name": item.get("name", ""),
"image": image_url,
"tags": [t["name"] for t in item.get("tags", [])],
"tags": [t.get("name", "") for t in item.get("tags", []) if t.get("name")],
"url": f"{self.base_url}/g/home/r/{item['slug']}",
})
return {
@@ -177,7 +177,7 @@ class MealieClient:
instructions.append(text)
# Parse tags
tags = [t["name"] for t in data.get("tags", [])]
tags = [t.get("name", "") for t in data.get("tags", []) if t.get("name")]
# Image URL
image_url = ""
+3 -3
View File
@@ -105,7 +105,7 @@ class TandoorClient:
"id": item["id"],
"name": item.get("name", ""),
"image": item.get("image") or "",
"tags": [k["name"] for k in item.get("keywords", [])],
"tags": [k.get("name", "") for k in item.get("keywords", []) if k.get("name")],
"url": f"{self.base_url}/view/recipe/{item['id']}",
})
return {
@@ -156,7 +156,7 @@ class TandoorClient:
instructions.append(text)
# Parse tags
tags = [k["name"] for k in data.get("keywords", [])]
tags = [k.get("name", "") for k in data.get("keywords", []) if k.get("name")]
return {
"title": data.get("name", ""),
@@ -202,7 +202,7 @@ class TandoorClient:
if source == url or url in desc:
return {
"id": item["id"],
"name": item["name"],
"name": item.get("name", ""),
"url": f"{self.base_url}/view/recipe/{item['id']}",
}
return None