anki-sync-server icon indicating copy to clipboard operation
anki-sync-server copied to clipboard

How to handle CollectionHandler.answer_card() / .next_card() when scheduler isn't setup?

Open dsnopek opened this issue 12 years ago • 0 comments

Here is the stacktrace seen in the wild:

Unable to answer_card(*[<AnkiServer.apps.rest_app.RestHandlerRequest object at 0x179da50>], **{}): 'Scheduler' object has no attribute 'lrnCount'
Traceback (most recent call last):
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/threading.py", line 95, in _run
    ret = self.wrapper.execute(func, args, kw, return_queue)
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/collection.py", line 58, in execute
    ret = func(*args, **kw)
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/apps/rest_app.py", line 561, in answer_card
    col.sched.answerCard(card, ease)
  File "/usr/share/anki/anki/sched.py", line 74, in answerCard
    self._answerLrnCard(card, ease)
  File "/usr/share/anki/anki/sched.py", line 549, in _answerLrnCard
    self.lrnCount += card.left // 1000
AttributeError: 'Scheduler' object has no attribute 'lrnCount'

It happens when a review is started (reset_scheduler(), next_card()), the Collection is closed for inactivity, and THEN the user does answer_card(). The Collection is re-opened, but reset_scheduler() isn't run.

The error will only appear when the card is in the "learning" queue, but it's probably a problem in many other cases. For example, .next_card() won't necessarily know the current deck and so who knows what it will return!

Additionally, in the specific case of answer_card(), we're marking as @noReturnValue, so the error never bubbles up to user. They don't even know that their answer wasn't recorded. :-/

Beyond this specific issue, this is a problem of using a stateless protocol (HTTP) to work with an inherently stateful system (Anki). I'm not sure what the full solution is... Maybe passing some sort of session setup information with every call to .next_card() and .answer_card()? That way, if the schedule isn't setup, it can be re-setup?

I'm not yet sure how to handle this...

dsnopek avatar Sep 14 '13 12:09 dsnopek