Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

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

Open
sosie-js opened this issue Aug 31, 2021 · 2 comments

Comments

@sosie-js
Copy link

sosie-js commented Aug 31, 2021

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

@sosie-js sosie-js changed the title def deleteDecks(self, decks, cardsToo=False): deleteDecks raises Exception(response["error"]) : rem() takes 2 positional arguments but 3 were given Aug 31, 2021
@oakkitten oakkitten mentioned this issue Mar 22, 2022
4 tasks
@Bar0-dev
Copy link

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
Copy link
Contributor

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

@util.api()
def deleteDecks(self, decks, cardsToo=False):
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)
finally:
self.stopEditing()

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()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants