Changed notes do not get updated after changing note type

I use genanki (a Python module) to create an Anki deck. The documentation of genanki says:

Note s have a guid property that uniquely identifies the note. If you import a new note that has the same GUID as an existing note, the new note will overwrite the old one (as long as their models have the same fields).
This is an important feature if you want to be able to tweak the design/content of your notes, regenerate your deck, and import the updated version into Anki. Your notes need to have stable GUIDs in order for the new note to replace the existing one.

Initially, I had a deck with two fields, let’s call them A and B. I added notes and imported them into Anki.

I then added a third field, Audio. In Anki, I changed the note type to add this field. In my program, I ensured that only fields A and B would be used for the GUID of the note, i.e. the GUIDs didn’t change when I added the Audio field.

When I now try to import the new deck into Anki (deskop or Android), I get:

Notes found in file: 1
Notes skipped, as they’re already in your collection: 1

I don’t understand why it’s not being imported. While the GUID is the same, the modification time is different and the Audio field has a value now whereas the note in Anki has an empty value.

I can make an example deck available if that would help.

BTW, if the first deck I create has all three fields (i.e. there’s no need to change the note type in Anki to add the Audio field), then the import works fine.

Did you select the Update existing notes when first field matches option when importing?
image

Is this option available on Linux? I don’t see it anywhere.

Also, is there a reason this isn’t done by default?

It’s in the drop-down menu.

image

I don’t see such an import menu anywhere. On Linux, I only get a file browser when I click on import.

You should see the import dialog after selecting a file. What Anki version are you using?

When I click on “File: Import…” or “Import File”, I get a file browser. When I click on a file and press “Open”, I see “Processing…” and the file is imported. There is no screen with options. I also don’t see any option to enable more import options.

I’ve tried both with 2.1.8 from Debian (quite old, I know) and with 2.1.33 from Flatpak.

Sorry, I misunderstood you. That dialog shows when importing text files…

Oh yes, I’m importing .apkg files.

Could you do that please?

@abdo thanks for your help.

git clone https://github.com/tbm/anki-test-note-type-change
  • Import test1.apkg into Anki
  • Go to Tools : Manage Note Types, look for the TEST Swahili vocabulary note note type and add a third field called Audio
  • Import test2.apkg - Anki says that nothing changed, but that’s clearly not true because the note has info in the Audio field.

test1.apkg has:

1|O);*8+=E!d|1325469472|1599619997|-1|  |moja (number)one|moja (number)|0|0|

test2.apkg has:

1|O);*8+=E!d|1325469472|1599619998|-1|  |moja (number)one[sound:Sw-ke-moja.opus]|moja (number)|0|0|

You see that the guid is the same. The mod is newer. And flds is clearly different: there’s info for the Audio field now - but this info doesn’t get applied during the update.

When you add the Audio field, the note modification time changes and becomes more recent than the note in test2.apkg, as a result, when you import test2.apkg, the note won’t be updated since it’s older.

I can confirm that by putting some debug statements in the import code to inspect modification time and running from source.

1 Like

Yeah, that makes sense. But I’m pretty sure I re-generated test2.apkg after doing the note modification but that import also failed.

Can you run gen-test2 to regenerate test2.apkg to see if that makes a difference. You only need pip3 install genanki for it to work.

It works for me after regenerating test2.apkg

image

1 Like

Hmm, I just regenerated test2.apkg locally (after modifying the note type) and imported it and now it works. So you were right.

But I’m pretty sure this didn’t work on my phone on the weekend. Maybe there’s an AnkiDroid issue. I’ll investigate.

But yes, the behaviour makes absolute sense, so I don’t think there’s any issue with Anki here. Thanks for yourtime @abdo.

If you do have time, could you take a look at the other forum post I made. Maybe you have an idea.

1 Like

@abdo Sorry for the late reply. I did test with AnkiDroid and it also worked there, so I think there’s no Anki issue.

I think your diagnosis is correct. Thanks again!