fail gracefully if id doesn't exist

This commit is contained in:
Damien Elmes 2008-10-02 17:08:00 +09:00
parent 85c72a9ddb
commit 6d721a3d86
2 changed files with 7 additions and 1 deletions

View file

@ -149,6 +149,8 @@ class Card(object):
def fromDB(self, s, id): def fromDB(self, s, id):
r = s.first("select * from cards where id = :id", r = s.first("select * from cards where id = :id",
id=id) id=id)
if not r:
return
(self.id, (self.id,
self.factId, self.factId,
self.cardModelId, self.cardModelId,
@ -187,6 +189,7 @@ class Card(object):
self.isDue, self.isDue,
self.type, self.type,
self.combinedDue) = r self.combinedDue) = r
return True
def toDB(self, s): def toDB(self, s):
"Write card to DB. Note that isDue assumes card is not spaced." "Write card to DB. Note that isDue assumes card is not spaced."

View file

@ -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." "Given a card ID, return a card, and start the card timer."
if orm: if orm:
card = self.s.query(anki.cards.Card).get(id) card = self.s.query(anki.cards.Card).get(id)
if not card:
return
card.timerStopped = False card.timerStopped = False
else: else:
card = anki.cards.Card() card = anki.cards.Card()
card.fromDB(self.s, id) if not card.fromDB(self.s, id):
return
card.genFuzz() card.genFuzz()
card.startTimer() card.startTimer()
return card return card