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

error: list index out of range #1

Closed galantra closed 5 years ago

galantra commented 5 years ago

I tried to copy a note. The following error appeared. When syncing, anki says that there are cards which have no note. I can delete the cards with "check database".

Error An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed. If the issue only occurs when add-ons are enabled, please use the Tools>Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem. When you've discovered the add-on that is causing the problem, please report the issue on the add-ons section of our support site. Debug info: Anki 2.1.15 (6661ba8a) Python 3.6.7 Qt 5.12.1 PyQt 5.11.3 Platform: Windows 10 Flags: frz=True ao=True sv=1

Caught exception: File "C:\Users\user\AppData\Roaming\Anki2\addons21\1566928056\copyNote.py", line 57, in a.triggered.connect(lambda : copyNotes(browser.selectedNotes())) File "C:\Users\Jo\AppData\Roaming\Anki2\addons21\1566928056\copyNote.py", line 46, in copyNotes copyNote(nid) File "C:\Users\Jo\AppData\Roaming\Anki2\addons21\1566928056\copyNote.py", line 76, in copyNote card.flush() File "", line 2, in flush File "anki\hooks.py", line 74, in decorator_wrapper File "anki\hooks.py", line 66, in repl File "C:\Users\Jo\AppData\Roaming\Anki2\addons21\865767531__init.py", line 180, in update_caches_for_card self.add_cards_to_caches(s.col, [s.id], update=True) File "C:\Users\Jo\AppData\Roaming\Anki2\addons21\865767531\init.py", line 100, in add_cards_to_caches qa = self.get_card_qa(collection, card_id) File "C:\Users\Jo\AppData\Roaming\Anki2\addons21\865767531\init__.py", line 72, in get_card_qa return collection.renderQA([card_id])[0] <class 'IndexError'>: list index out of range

Arthur-Milchior commented 5 years ago

You can see add-on number 865767531 at the end of the error message. The reason it's here is that the bug comes from the interaction between both add-ons. I see no way of fixing this bug without changing both add-ons simultaneously; so currently I won't do anything with it unless more people tell me they do use both add-ons.

The main cause of the problem as far as I understand it, is that collection._qaData queries cards c by requesting that there is a note f such that c.nid = f.id. The trouble being that while I flush the card, the note to which it is associated is not already in the database. Which means that the whole renderQA process can't be done, since there is no way for it to have access to any fields. This problem never occurs outside of this add-on because notes are flushed before cards usually

One trouble is that I can't easily flush note before cards in the add-on, otherwise the cards would be generated, and instead of creating copies of current card, it'll create whole new cards. I could then edit those cards so that they become copy. But honestly, it seems to be a way to introduce bugs, without giving anything interesting (appart from the fact that It'll be compatible with add-on 865767531)

galantra commented 5 years ago

Thank you, all right. I have uninstalled 865767531 (show duplicates). Working fine now. Also, I've learned to understand the error message.