From 8497da27cf47f395a8288c47d9ff3ba32e95cfc4 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 21 Apr 2019 18:02:12 +1000 Subject: [PATCH] ensure the list of note types is not empty fixes an issue opening the add screen if a user manages to delete all their note types with an add-on or a sync --- anki/collection.py | 3 +++ anki/models.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/anki/collection.py b/anki/collection.py index 60ac01441..c9f93618a 100644 --- a/anki/collection.py +++ b/anki/collection.py @@ -872,6 +872,9 @@ and type = 0""", intTime(), self.usn()) curs.execute("update revlog set ivl=round(ivl),lastIvl=round(lastIvl) where ivl!=round(ivl) or lastIvl!=round(lastIvl)") if curs.rowcount: problems.append("Fixed %d review history entries with v2 scheduler bug." % curs.rowcount) + # models + if self.models.ensureNotEmpty(): + problems.append("Added missing note type.") # and finally, optimize self.optimize() newSize = os.stat(self.path)[stat.ST_SIZE] diff --git a/anki/models.py b/anki/models.py index 9da5822bb..d37b7e24e 100644 --- a/anki/models.py +++ b/anki/models.py @@ -96,10 +96,17 @@ class ModelManager: def flush(self): "Flush the registry if any models were changed." if self.changed: + self.ensureNotEmpty() self.col.db.execute("update col set models = ?", json.dumps(self.models)) self.changed = False + def ensureNotEmpty(self): + if not self.models: + from anki.stdmodels import addBasicModel + addBasicModel(self.col) + return True + # Retrieving and creating models #############################################################