From dd0e56afb36d1ce88c40a81a1c9e0b901f2bc157 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Fri, 24 Jun 2022 05:57:42 +0200 Subject: [PATCH] Handle note without cards in browser (#1929) Change the IndexError to a NotFoundError which is picked up by the table model. --- qt/aqt/browser/table/state.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qt/aqt/browser/table/state.py b/qt/aqt/browser/table/state.py index 0bbe74d44..579b9f2ab 100644 --- a/qt/aqt/browser/table/state.py +++ b/qt/aqt/browser/table/state.py @@ -8,6 +8,7 @@ from typing import Sequence, cast from anki.browser import BrowserConfig from anki.cards import Card, CardId from anki.collection import Collection +from anki.errors import NotFoundError from anki.notes import Note, NoteId from anki.utils import ids2str from aqt.browser.table import Column, ItemId, ItemList @@ -191,7 +192,9 @@ class NoteState(ItemState): self.col.set_browser_note_columns(self._active_columns) def get_card(self, item: ItemId) -> Card: - return self.get_note(item).cards()[0] + if cards := self.get_note(item).cards(): + return cards[0] + raise NotFoundError def get_note(self, item: ItemId) -> Note: return self.col.get_note(NoteId(item))