anki-connect
anki-connect copied to clipboard
deleteDecks does not work on 2.1.44 due to changes to Anki's DeckManager rem function
The latest release of Anki, 2.1.44, requires both cardsToo and childrenToo to be set to true when calling rem on a DeckManager:
def rem(self, did: int, cardsToo: bool = True, childrenToo: bool = True) -> None:
"Remove the deck. If cardsToo, delete any cards inside."
if isinstance(did, str):
did = int(did)
assert cardsToo and childrenToo
self.col._backend.remove_deck(did)
AnkiConnect passes down cardsToo, which will result in an AssertionError if cardsToo is set to false (which is also the default).
As a result, not only is the deck not deleted, the way AnkiConnect parses the exception means that the return will have an empty string in the error field {"error": ""}. This is different from the success case {"error": null}, but still not ideal. If the string representation of an exception is empty, then AnkiConnect should return a fallback string.
To fix the issue I would:
- If the user set
cardsToototrue, then perform the deletion and return a deprecation warning thatcardsToohas no effect and will always be true in the future - If the user did not set
cardsTooor set it tofalse, then don't delete the deck and just return an error stating that it is not possible to delete the deck without also removing cards.
Note that rem will also be deprecated in the next releases for remove, which no longer has any cardsToo parameter.
For reference, here's the code to the new remove function: https://github.com/ankitects/anki/blob/1cdf0b1e9d86d3ac453118dfb59aa55b90630ece/pylib/anki/decks.py#L147
Does anyone know if calling remove will remove the cards? What about if it's a filtered deck? I don't understand this new code...
Does anyone know if calling remove will remove the cards?
I don't understand the code neither but it seems to delete the files too.
self.decks().remove([did])
col = Collection("path/to/collection.anki2")
col.db.all("select count() from cards")
# [[0]]