Gustaf-C / anki-chinese-support-3

Anki add-on providing support for Chinese study
https://ankiweb.net/shared/info/1752008591
GNU General Public License v3.0
26 stars 7 forks source link

Can't bulk fill after switching profiles #18

Closed Gustaf-C closed 8 months ago

Gustaf-C commented 8 months ago

Other fills seem to work fine.

Caught exception: Traceback (most recent call last): File "/Library/Application Support/Anki2/addons21/chinese/fill.py", line 96, in bulk_fill_all n_updated += update_fields(note, 'Hanzi', fields) File "/Library/Application Support/Anki2/addons21/chinese/behavior.py", line 311, in update_fields fill_all_defs(hanzi, copy) File "/Library/Application Support/Anki2/addons21/chinese/behavior.py", line 96, in fill_all_defs fill_def(hanzi, note, lang='en'), File "Library/Application Support/Anki2/addons21/chinese/behavior.py", line 74, in fill_def classifier = get_classifier(hanzi, note) File "Library/Application Support/Anki2/addons21/chinese/behavior.py", line 45, in get_classifier cs = dictionary.get_classifiers(hanzi) File "Library/Application Support/Anki2/addons21/chinese/database.py", line 219, in get_classifiers self.c.execute( sqlite3.ProgrammingError: Cannot operate on a closed database.

kieranlblack commented 8 months ago

I ran into this issue with simple definition generation too, not just with bulk mode. Since addons are shared across plugins, the source of the error seems to be here:

https://github.com/Gustaf-C/anki-chinese-support-3/blob/86d8beac838a60f564125104ed8cdd4172d6aa84/chinese/main.py#L49

There doesn't seem to be a hook for exiting and this has the right spirit, its just that the Dictionary instantiation at the global scope isn't quite there. We can add a profile_did_open hook to set up the connection to the database, rather than doing so in the constructor.

Gustaf-C commented 8 months ago

Thanks for the pointer, was a quick fix