Arthur-Milchior / anki-copy-note

An add-on to copy anki's note
GNU General Public License v3.0
23 stars 9 forks source link

copyNote fix for 2.1.38 #23

Open garrett92895 opened 3 years ago

garrett92895 commented 3 years ago

This is a fix for #20 and possible #19

I was running into an issue on 2.1.38 when trying to copy a note

Caught exception:
Traceback (most recent call last):
  File "/Users/garrett2/Library/Application Support/Anki2/addons21/1566928056/copyNote.py", line 65, in <lambda>
    a.triggered.connect(lambda: copyNotes(browser.selectedNotes()))
  File "/Users/garrett2/Library/Application Support/Anki2/addons21/1566928056/copyNote.py", line 52, in copyNotes
    copyNote(nid)
  File "/Users/garrett2/Library/Application Support/Anki2/addons21/1566928056/copyNote.py", line 83, in copyNote
    note.flush()
  File "anki/notes.py", line 68, in flush
  File "anki/rsbackend_gen.py", line 364, in update_note
  File "anki/rsbackend.py", line 256, in _run_command

I drilled down and found the source of the issue was some newly added error handling. See this issue for more details.

The solution was to use addNote instead. I also had to set the id to 0 first because of a rust assertion.

Keep in mind, addNote in collection.py is legacy and likely to break again. add_note should be used instead, but it requires you to provide a deck_id and this PR only contains the code changes that I was able to get working on my machine.