Skip to content

Commit 492cd02

Browse files
fix: ensure only valid IMDb IDs are returned in metadata cleaning
1 parent 1d25318 commit 492cd02

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app/api/endpoints/catalogs.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ def _clean_meta(meta: dict) -> dict:
4040
cleaned = {k: v for k, v in meta.items() if k in allowed}
4141
# Drop empty values
4242
cleaned = {k: v for k, v in cleaned.items() if v not in (None, "", [], {}, ())}
43-
# only return values with imdb id
44-
cleaned = {k: v for k, v in cleaned.items() if k == "id" and v.startswith("tt")}
43+
44+
# if id does not start with tt, return None
45+
if not cleaned.get("id", "").startswith("tt"):
46+
return None
4547
return cleaned
4648

4749

@@ -197,6 +199,8 @@ def _get_limits() -> tuple[int, int]:
197199
logger.info(f"Returning {len(recommendations)} items for {type}")
198200
response.headers["Cache-Control"] = "public, max-age=21600" # 6 hours
199201
cleaned = [_clean_meta(m) for m in recommendations]
202+
# remove none values
203+
cleaned = [m for m in cleaned if m is not None]
200204
return {"metas": cleaned}
201205

202206
except HTTPException:

0 commit comments

Comments
 (0)