From b2caaa8bc390024fd57751d1b2b029c46c9517da Mon Sep 17 00:00:00 2001 From: ducklet Date: Fri, 6 Aug 2021 12:56:01 +0200 Subject: [PATCH] fix updating user ratings from IMDb We need to use the existing user from the DB to avoid overwriting the user's secret or other details. We also can't assert the user will stay the same, because at least their name is allowed to change. --- unwind/imdb.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/unwind/imdb.py b/unwind/imdb.py index 0da9091..666f8ed 100644 --- a/unwind/imdb.py +++ b/unwind/imdb.py @@ -45,7 +45,7 @@ async def refresh_user_ratings_from_imdb(stop_on_dupe=True): log.info("⚡️ Loading data for %s ...", user.name) async for rating, is_updated in load_ratings(user.imdb_id): - assert rating.user == user + assert rating.user.id == user.id if stop_on_dupe and not is_updated: break @@ -156,7 +156,10 @@ async def parse_page(url) -> Tuple[list[Rating], Optional[str]]: meta = soup.find("meta", property="pageId") headline = soup.h1 assert meta is not None and headline is not None - user = User(imdb_id=meta["content"], name="") + imdb_id = meta["content"] + user = await db.get(User, imdb_id=imdb_id) or User( + imdb_id=imdb_id, name="", secret="" + ) if match := find_name(headline.string): user.name = match["name"]