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):
|
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."
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue