Problem 1: Reimport fails completely (all exercises fail)
Root cause: Line 465 existing[0] instead of existing['id']
Fix: Changed to existing['id'] for dict-cursor compatibility
Problem 2: 221 exercises skipped, only 2 in database
Root cause: Orphaned wiki_import_references from failed imports
Fix: New admin endpoint to manually cleanup orphaned references
New endpoints:
- DELETE /api/import/mediawiki/admin/cleanup-orphaned-references
Deletes all references where local_id doesn't exist in target table
Returns count of deleted references per type
- GET /api/import/mediawiki/admin/stats
Shows references vs. actual count + orphaned count
Helps diagnose import state issues
Usage:
1. Call cleanup endpoint to remove orphaned references
2. Run normal import (reimport=false)
3. Should import all previously failed exercises