compat fixes for add-on usage of col.decks.active()

This commit is contained in:
Damien Elmes 2021-05-19 15:41:37 +10:00
parent 9f3f6bab7d
commit 590ef6da0a
2 changed files with 16 additions and 2 deletions

View file

@ -477,7 +477,8 @@ class DeckManager:
self.col.reset()
def active(self) -> List[DeckId]:
return self.col.sched.active_decks
# some add-ons assume this will always be non-empty
return self.col.sched.active_decks or [DeckId(1)]
selected = get_current_id

View file

@ -11,12 +11,14 @@ as '2' internally.
from __future__ import annotations
from typing import Literal, Sequence, Tuple, Union
from typing import List, Literal, Sequence, Tuple, Union
import anki._backend.backend_pb2 as _pb
from anki.cards import Card, CardId
from anki.collection import OpChanges
from anki.consts import *
from anki.decks import DeckId
from anki.errors import DBError
from anki.scheduler.base import CongratsInfo
from anki.scheduler.legacy import SchedulerBaseWithLegacy
from anki.types import assert_exhaustive
@ -239,3 +241,14 @@ class Scheduler(SchedulerBaseWithLegacy):
assert False, "invalid ease"
return self._interval_for_state(new_state)
# Other legacy
###################
# called by col.decks.active(), which add-ons are using
@property
def active_decks(self) -> List[DeckId]:
try:
return self.col.db.list("select id from active_decks")
except DBError:
return []