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

database use after close #67

Open kieranlblack opened 4 months ago

kieranlblack commented 4 months ago

Describe the bug Closed database checks still not right. I'm still getting a use after close error:

Traceback (most recent call last):
  File "C:\Users\kiera\git\anki\qt\aqt\webview.py", line 50, in cmd
    return json.dumps(self.onCmd(str))
  File "C:\Users\kiera\git\anki\qt\aqt\webview.py", line 157, in _onCmd
    return self._onBridgeCmd(str)
  File "C:\Users\kiera\git\anki\qt\aqt\webview.py", line 686, in _onBridgeCmd
    return self.onBridgeCmd(cmd)
  File "C:\Users\kiera\git\anki\qt\aqt\editor.py", line 425, in onBridgeCmd
    if gui_hooks.editor_did_unfocus_field(False, self.note, ord):
  File "C:\Users\kiera\git\anki\out/qt\_aqt\hooks.py", line 2548, in __call__
    changed = anki.hooks.runFilter(
  File "C:\Users\kiera\git\anki\pylib\anki\hooks.py", line 45, in runFilter
    arg = func(arg, *args)
  File "C:\Users\kiera\coding\anki-chinese-support-3\addons21\anki-chinese-support-3\chinese\edit.py", line 122, in onFocusLost
    if not update_fields(note, field, allFields):
  File "C:\Users\kiera\coding\anki-chinese-support-3\addons21\anki-chinese-support-3\chinese\behavior.py", line 346, in update_fields
    fill_alt(hanzi, copy)
  File "C:\Users\kiera\coding\anki-chinese-support-3\addons21\anki-chinese-support-3\chinese\behavior.py", line 99, in fill_alt
    alts = dictionary.get_variants(hanzi)
  File "C:\Users\kiera\coding\anki-chinese-support-3\addons21\anki-chinese-support-3\chinese\database.py", line 246, in get_variants
    self.c.execute(
sqlite3.ProgrammingError: Cannot operate on a closed database.

To Reproduce

  1. open add new card window
  2. fill in hanzi field
  3. click close on main window
  4. trigger fill with any sort of event on the add window
  5. see error above

Probably because the handler for closing is being called even though the add window is still open. Might be an Anki issue tbh but we can at least account for it.

Gustaf-C commented 4 months ago

Yeah it seems like the profile_will_close hooks is triggered when the main window is closed, which leads to issues when other windows are open. I don't think that is intended behaviour.