From 58370d67573f92a09578147592ac883a7e39f67b Mon Sep 17 00:00:00 2001 From: RumovZ Date: Wed, 18 May 2022 05:34:51 +0200 Subject: [PATCH] Fix #1874 (#1875) Probably a race condition. `.get_row()` is not a reliable check for card or note existence, because it returns from an outdated cache, if the backend is currently blocked. --- qt/aqt/browser/table/model.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/qt/aqt/browser/table/model.py b/qt/aqt/browser/table/model.py index 6d50d6174..77ff44b9f 100644 --- a/qt/aqt/browser/table/model.py +++ b/qt/aqt/browser/table/model.py @@ -216,11 +216,14 @@ class DataModel(QAbstractTableModel): """Try to return the indicated, possibly deleted card.""" if not index.isValid(): return None - # The browser code will be calling .note() on the returned card. - # This implicitly ensures both the card and its note exist. - if self.get_row(index).is_disabled: + # The browser code will be calling .note() on the returned card, but + # the note might have been be deleted while the card still exists. + try: + card = self._state.get_card(self.get_item(index)) + card.note() + except NotFoundError: return None - return self._state.get_card(self.get_item(index)) + return card def get_note(self, index: QModelIndex) -> Note | None: """Try to return the indicated, possibly deleted note."""