From cc027f8ab80fbafd8bd874d32bbe701ad2391e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Matthias=20Sch=C3=A4fer?= Date: Sat, 5 Oct 2024 13:26:28 +0200 Subject: [PATCH] Replace calls to deprecated flush() with col.update_note/card The changes passes skip_undo_entry to update_note/card, because the implementation of the deprecated flush() method did so. Whether this is the right decision for our use case was not checked/thought about. --- plugin/__init__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugin/__init__.py b/plugin/__init__.py index e433c5f..ab3e63f 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -829,7 +829,7 @@ class AnkiConnect: pictureObjectOrList = note.get('picture') self.addMedia(ankiNote, pictureObjectOrList, util.MediaType.Picture) - ankiNote.flush() + self.collection().update_note(ankiNote, skip_undo_entry=True); @util.api() @@ -893,8 +893,8 @@ class AnkiConnect: # Update the tags anki_note.tags = new_tags - # Flush changes to ensure they are saved - anki_note.flush() + # Update note to ensure changes are saved + collection.update_note(anki_note, skip_undo_entry=True); @util.api() def updateNoteTags(self, note, tags): @@ -948,7 +948,7 @@ class AnkiConnect: if note.has_tag(tag_to_replace): note.remove_tag(tag_to_replace) note.add_tag(replace_with_tag) - note.flush() + self.collection().update_note(note, skip_undo_entry=True); self.window().requireReset() self.window().progress.finish() @@ -965,7 +965,7 @@ class AnkiConnect: if note.has_tag(tag_to_replace): note.remove_tag(tag_to_replace) note.add_tag(replace_with_tag) - note.flush() + self.collection().update_note(note, skip_undo_entry=True); self.window().requireReset() self.window().progress.finish() @@ -984,7 +984,7 @@ class AnkiConnect: couldSetEaseFactors.append(True) ankiCard.factor = easeFactors[i] - ankiCard.flush() + self.collection().update_card(ankiCard, skip_undo_entry=True) return couldSetEaseFactors @@ -1014,7 +1014,7 @@ class AnkiConnect: ankiCard = self.getCard(card) for i, key in enumerate(keys): setattr(ankiCard, key, newValues[i]) - ankiCard.flush() + self.collection().update_card(ankiCard, skip_undo_entry=True) result.append(True) except Exception as e: result.append([False, str(e)])