anki-connect icon indicating copy to clipboard operation
anki-connect copied to clipboard

updateNoteFields returns errorless but does nothing

Open zacharied opened this issue 7 years ago • 16 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.

zacharied avatar Jun 17 '18 20:06 zacharied

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

sintak avatar Jul 13 '18 16:07 sintak

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 }

redstoneleo avatar Oct 30 '18 04:10 redstoneleo

Try adding modelName and deckName. Works for me now.

masteranza avatar Mar 24 '19 01:03 masteranza

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

garrett-hopper avatar Jun 05 '19 02:06 garrett-hopper

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

garrett-hopper avatar Jun 05 '19 02:06 garrett-hopper

I should not I'm on Anki 2.1.11.

garrett-hopper avatar Jun 07 '19 02:06 garrett-hopper

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

FooSoft avatar Jun 08 '19 23:06 FooSoft

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.

garrett-hopper avatar Jun 09 '19 02:06 garrett-hopper

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

FooSoft avatar Jun 09 '19 03:06 FooSoft

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.

garrett-hopper avatar Jun 09 '19 03:06 garrett-hopper

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

It works for me now, Thank you!

shanehh avatar May 30 '20 09:05 shanehh

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?

eyeinsky avatar Nov 01 '20 20:11 eyeinsky

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)

kondeeza avatar Nov 23 '20 09:11 kondeeza

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!

Twinov avatar Jul 26 '21 04:07 Twinov

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.

Aquafina-water-bottle avatar Aug 22 '22 06:08 Aquafina-water-bottle

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

chenlijun99 avatar Apr 11 '23 22:04 chenlijun99