CRITICAL: Fix database upsert bug preventing manual scan date persistence
**Root Cause**: upsert_movie_dates() was UPDATE-only, not proper upsert - Manual scans failed to save dateadded to database (NULL values) - Webhooks found database entries but with NULL dateadded - Fell back to current timestamp instead of using proper import dates **Database Fix**: - Changed core/database.py upsert_movie_dates() from UPDATE to INSERT OR REPLACE - Now properly saves dateadded during manual scans - Preserves existing path with COALESCE fallback **Webhook Enhancement**: - Added comprehensive debug logging for database lookups - Enhanced webhook date decision logic with proper fallback chain - Only uses current timestamp as absolute last resort **Impact**: - Movies: Manual scans now persist dates, webhooks find existing entries ✅ - TV Shows: Not affected - already using proper INSERT OR REPLACE ✅ - Version: 1.5.5
This commit is contained in:
+8
-4
@@ -175,11 +175,15 @@ class NFOGuardDatabase:
|
||||
"""Insert or update movie date record"""
|
||||
with self.get_connection() as conn:
|
||||
cursor = conn.cursor()
|
||||
# Use INSERT OR REPLACE to ensure we always update the dates properly
|
||||
cursor.execute("""
|
||||
UPDATE movies
|
||||
SET released = ?, dateadded = ?, source = ?, has_video_file = ?, last_updated = ?
|
||||
WHERE imdb_id = ?
|
||||
""", (released, dateadded, source, has_video_file, datetime.utcnow().isoformat(), imdb_id))
|
||||
INSERT OR REPLACE INTO movies (imdb_id, path, released, dateadded, source, has_video_file, last_updated)
|
||||
VALUES (
|
||||
?,
|
||||
COALESCE((SELECT path FROM movies WHERE imdb_id = ?), 'unknown'),
|
||||
?, ?, ?, ?, ?
|
||||
)
|
||||
""", (imdb_id, imdb_id, released, dateadded, source, has_video_file, datetime.utcnow().isoformat()))
|
||||
|
||||
def get_series_episodes(self, imdb_id: str, has_video_file_only: bool = False) -> List[Dict]:
|
||||
"""Get all episodes for a series"""
|
||||
|
||||
Reference in New Issue
Block a user