From 993e6ba7d50e8e9553e9abd4a65f9ce3cae0141d Mon Sep 17 00:00:00 2001 From: npeter83 Date: Tue, 16 Jun 2026 00:11:58 +0200 Subject: [PATCH] fix(playlists): dirty lagged one edit (flush before fingerprinting) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The session has autoflush off, so recompute_dirty's query read the last-committed state, not the current request's pending item/order edits — so the first reorder after a sync compared against itself and missed dirty, and only the next edit showed it. Flush pending changes before computing the current fingerprint. Verified: a swap now flips dirty immediately, and reverting to the original clears it. --- backend/app/sync/playlists.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/app/sync/playlists.py b/backend/app/sync/playlists.py index 764ad7d..bb60489 100644 --- a/backend/app/sync/playlists.py +++ b/backend/app/sync/playlists.py @@ -43,8 +43,11 @@ def recompute_dirty(db: Session, pl: Playlist) -> None: (and Watch later) are never dirty; a missing baseline counts as dirty (unknown YT state).""" if not pl.yt_playlist_id: pl.dirty = False - else: - pl.dirty = pl.synced_fingerprint != current_fingerprint(db, pl) + return + # The session has autoflush off, so the caller's pending item/order/name edits aren't + # visible to current_fingerprint's query yet — flush first or dirty would lag one edit. + db.flush() + pl.dirty = pl.synced_fingerprint != current_fingerprint(db, pl) def _ensure_videos(db: Session, yt: YouTubeClient, video_ids: list[str]) -> None: