mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
fail gracefully if id doesn't exist
This commit is contained in:
parent
85c72a9ddb
commit
6d721a3d86
2 changed files with 7 additions and 1 deletions
|
@ -149,6 +149,8 @@ class Card(object):
|
|||
def fromDB(self, s, id):
|
||||
r = s.first("select * from cards where id = :id",
|
||||
id=id)
|
||||
if not r:
|
||||
return
|
||||
(self.id,
|
||||
self.factId,
|
||||
self.cardModelId,
|
||||
|
@ -187,6 +189,7 @@ class Card(object):
|
|||
self.isDue,
|
||||
self.type,
|
||||
self.combinedDue) = r
|
||||
return True
|
||||
|
||||
def toDB(self, s):
|
||||
"Write card to DB. Note that isDue assumes card is not spaced."
|
||||
|
|
|
@ -205,10 +205,13 @@ Caller is responsible for ensuring cards are not spaced."""
|
|||
"Given a card ID, return a card, and start the card timer."
|
||||
if orm:
|
||||
card = self.s.query(anki.cards.Card).get(id)
|
||||
if not card:
|
||||
return
|
||||
card.timerStopped = False
|
||||
else:
|
||||
card = anki.cards.Card()
|
||||
card.fromDB(self.s, id)
|
||||
if not card.fromDB(self.s, id):
|
||||
return
|
||||
card.genFuzz()
|
||||
card.startTimer()
|
||||
return card
|
||||
|
|
Loading…
Reference in a new issue