FooSoft / anki-connect

Anki plugin to expose a remote API for creating flash cards.

Home Page:https://foosoft.net/projects/anki-connect/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

updateNoteFields returns errorless but does nothing

zacharied opened this issue · comments

I have been trying to write a program that inserts example sentences into a vocabulary deck using a few APIs, but have gotten hung up because updateNoteFields seems to do nothing. I can run noteInfo and get the note's information fine, but running updateNoteFields on the same note ID seems to do nothing. The request also returns "error": null despite clearly not following intended behavior.

commented

I try this Action, and then it returns: {result: null, error: 'NoneType' object is not iterable}

I met with the same issue , but the cause in my case is I got the wrong note id( an id doesn't exist at all).
One could check with

findNotes

Returns an array of note IDs for a given query. Same query syntax as guiBrowse.

Sample request:

{
"action": "findNotes",
"version": 6,
"params": {
"query": "deck:current"
}
}
Sample result:

{
"result": [1483959289817, 1483959291695],
"error": null
}

Try adding modelName and deckName. Works for me now.

I'm observing the same behavior with the latest master branch.

After doing some debugging, it looks like the ankiNote is updated with the correct fields, but nothing is updated upon ankiNote.flush().

I should not I'm on Anki 2.1.11.

Just tested this on 2.1.13 and it appears to work fine for me. Can you try running the unit test and see if that fails for you (check test.sh).

Ah, it appears it doesn't work when the note browser is open. If I close the browser and then update a note, I can open it again and view the updated note.

The note browser probably resets the note to the previous value on close.

That'd make sense; I wonder if there's a way to live-update in the browser.
I suppose it's not really important for normal usage though.

commented

The note browser probably resets the note to the previous value on close.

It works for me now, Thank you!

I was struggling with the same issue with Anki 2.1.15 on Linux, and what @garrett-hopper says is correct: if the note browser is open then just running updateNoteFields doesn't appear to update the card in the browser.

Some additional observations:

  • if after the seemingly failed update one runs a successful addNote while the note browser still open, then both changes happen successfully (i.e are reflected in the note browser);
  • but if you close note browser and then run a successful addNote then the update is lost.

I wonder if this means that the update request is received but simply not shown in the note browser. And then when one closes the note browser it takes all the data from the note browser's view and overwrites the update -- effectively going back to the old value.

@FooSoft Perhaps this is a bug in the Anki program itself?

Could I suggest adding some clear warning in updateNoteFields's section of notes.md that having note browser would likely cause the note to not be updated even if the API returns a successful promise? I have a feeling first timer user and developer alike would be very tempted to keep browser gui open to handily see if the command works (which would backfire XD)

commented

Can I bump the request to add a warning to updateNoteFields in the README that having the GUI open causes it to not do anything? I just ran into this exact issue, ironically also writing a script to add example sentences to a vocabulary deck. Closing the GUI solved the issue though so thanks Garrett!

Just wanted to mention that for anyone writing scripts using updateNoteFields that there is a workaround: You can run guiBrowse to essentially refresh Anki's browser.

The order of API calls is the following:

  • guiBrowse with a query of nid:1 (or some other invalid note id, to clear the browser window)
  • updateNoteFields
  • guiBrowse with a query of nid:<your note id that you just updated>

Credits to this code in mpvacious for pointing it out in the comments.

Perhaps it is case-sensitive and you should use "Basic" instead of "basic"?