From bee3422a72b59172c97d6da8ab7f5a2f64f1dc43 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 23 Oct 2012 13:09:57 +0900 Subject: [PATCH] catch cards without template in db check --- anki/collection.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/anki/collection.py b/anki/collection.py index bcad89157..3ce5e4438 100644 --- a/anki/collection.py +++ b/anki/collection.py @@ -640,6 +640,19 @@ select id from notes where mid not in """ + ids2str(self.models.ids())) "Deleted %d notes with missing note type.", len(ids)) % len(ids)) self.remNotes(ids) + # cards with invalid ordinal + for m in self.models.all(): + ids = self.db.list(""" +select id from cards where ord not in %s and nid in ( +select id from notes where mid = ?)""" % + ids2str([t['ord'] for t in m['tmpls']]), + m['id']) + if ids: + problems.append( + ngettext("Deleted %d card with missing template.", + "Deleted %d cards with missing template.", + len(ids)) % len(ids)) + self.remCards(ids) # delete any notes with missing cards ids = self.db.list(""" select id from notes where id not in (select distinct nid from cards)""")