Anki: Allowing Import for My Flow
When after a couple of weeks, I wanted to import the script to another episode script to Anki for studying. I was enjoying the 世界最高の暗殺者、異世界貴族に転生する (The World's Finest Assassin Gets Reincarnated in Another World as an Aristocrat), and though it would be an interesting material.
But when I tried to import it in, I got the error, that my template is wrong. The error with the traceback is below:
Caught exception: Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/aqt/importing.py", line 197, in accept self.mw.col.models.save(self.importer.model, updateReqs=False) File "/usr/lib/python3.10/site-packages/anki/models.py", line 556, in save self.update(notetype, preserve_usn=False) File "/usr/lib/python3.10/site-packages/anki/models.py", line 539, in update notetype["id"] = self.col._backend.add_or_update_notetype( File "/usr/lib/python3.10/site-packages/anki/_backend/generated.py", line 450, in add_or_update_notetype output.ParseFromString(self._run_command(4, 4, input)) File "/usr/lib/python3.10/site-packages/anki/_backend/__init__.py", line 131, in _run_command raise backend_exception_to_pylib(err) anki.errors.TemplateError: Card template 1 in notetype 'Cloze Japanese Sentences' has a problem.<br>Expected to find '{{cloze:Text}}' or similar on the front and back of the card template.
I am using the Arch Linux anki packages (now installed from the AUR). The version of the Anki is 2.1.49 (nogit), with Python 3.10.1, Qt 5.15.2, and PyQt 5.15.6.
I am not sure, what the message is about. My first check was to trace the path through the tracepath. But while I realized, that I am not passing some checks, I could not figure out what kind of checks they were.
Looking at the template, the only think that I think of is that either:
- I do not cloze the first field - I am only having clozes in second and/or third field)
- I am not having any clozes in the cards importing - since I usually add it afterwards
Based on the message, the first one seem more plausible.
So what I did to resolve it for me, was to change the update function on the ModelManager class in the anki/models.py file. I added the default for skip_checks as True, instead of a False. In my version installed on the computer, this is line 534.
Since there is a commented out depreciated notice, it seems that this will be replaced sometime in the future. And this one does not have a skip_checks argument. So hopefully, this problem will simply disappear in the future. Unless these checks will all become mandatory, and I will need to find a better solution. :)
Until then, I guess I can just change it every time I update it. Since anki package was dropped to AUR, I need to update it manually and I will be aware of when this happens.