From c642d2125c039b2b3fbbff58251c9867616154a4 Mon Sep 17 00:00:00 2001 From: "mamonov.ep" Date: Mon, 12 Jan 2026 11:31:01 +0300 Subject: [PATCH] Fix duplicate theme insertion when API returns multiple versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../app/openings_downloader/services/animethemes.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/app/openings_downloader/services/animethemes.py b/backend/app/openings_downloader/services/animethemes.py index 3ec3578..26a9e45 100644 --- a/backend/app/openings_downloader/services/animethemes.py +++ b/backend/app/openings_downloader/services/animethemes.py @@ -205,11 +205,13 @@ class AnimeThemesService: key = (theme_type, sequence) if key in existing_themes: - # Update existing theme + # Update existing theme (skip if already has video_url) theme = existing_themes[key] - theme.song_title = song_title - theme.artist = artist - if video_url: + if not theme.song_title: + theme.song_title = song_title + if not theme.artist: + theme.artist = artist + if video_url and not theme.animethemes_video_url: theme.animethemes_video_url = video_url else: # Create new theme @@ -225,6 +227,8 @@ class AnimeThemesService: if anime.themes is None: anime.themes = [] anime.themes.append(theme) + # Add to existing_themes to avoid duplicates from API + existing_themes[key] = theme await db.commit()