FooSoft / anki-connect

Anki plugin to expose a remote API for creating flash cards.
https://foosoft.net/projects/anki-connect/
Other
1.94k stars 220 forks source link

deleteDecks raises Exception(response["error"]) : rem() takes 2 positional arguments but 3 were given #286

Open sosie-js opened 3 years ago

sosie-js commented 3 years ago

Konnitchiwa,

When using Ankisync2 deleteDecks sample from the readme or from the site

result = invoke("deleteDecks", decks=decks , cardsToo=cardsToo)

it is impossible to delete any deck., it raises Exception(response["error"]) Exception: rem() takes 2 positional arguments but 3 were given

Problem is, I guess it does not match the definition of api function declared ini.py def deleteDecks(self, decks, cardsToo=False):

as cardsToo initialisation seems to interfers, maybe the same issue with 272

It crashes the ankisync2_web.py script, part of ankisync2 with ExamplesDoc Auto-Generator extension

Bar0-dev commented 2 years ago

Calling deleteDecks with javascript as it is on the example with cardssToo: true still doesnt remove the deck. Im going to try to fix this issue soon since I need this fucntion to be working for my project.

oakkitten commented 2 years ago

I've been working on fixing the tests, for now i changed this

https://github.com/FooSoft/anki-connect/blob/54a7105bf9da31dabe884a96464206a0fc87c58d/plugin/__init__.py#L532-L541

to say

    @util.api()
    def deleteDecks(self, decks, cardsToo=False):
        if not cardsToo:
            # since f592672fa952260655881a75a2e3c921b2e23857 (2.1.28)
            # (see anki$ git log "-Gassert cardsToo")
            # you can't delete decks without deleting cards as well.
            # however, since 62c23c6816adf912776b9378c008a52bb50b2e8d (2.1.45)
            # passing cardsToo to `rem` (long deprecated) won't raise an error!
            # this is dangerous, so let's raise our own exception
            if self._anki21_version >= 28:
                raise Exception("Since Anki 2.1.28 it's not possible "
                                "to delete decks without deleting cards as well")
        try:
            self.startEditing()
            decks = filter(lambda d: d in self.deckNames(), decks)
            for deck in decks:
                did = self.decks().id(deck)
                self.decks().rem(did, cardsToo=cardsToo)
        finally:
            self.stopEditing()