anki-connect
anki-connect copied to clipboard
Duplicate check fails when media added to the Front Field
Hello,
When I did the API POST request below to add an Audio+Text note to my deck, several times, the duplicate check fails and note is added multiple times. This happens only when media (audio in my case) is in the Front field.
See my update below on the details and diagnosis of the issue.
After review similar past posts on duplicates commented by @jasonwilliams and @snoyes
Special characters break the allowDuplicate: false check #194 and Can't prevent duplicates from being added via API #164 @foosoft, I edited __init__.py
and run anki command line debug console. Jump to summary of the issue if you want to skip the steps.
1- Making Anki-Connect print the value of val and the value of csum

init.py line 291
val = note.fields[0]
print("the value that we are going to run a checksum on is \n"+val+" ")
init.py line 294
csum = anki.utils.fieldChecksum(val)
print("the checksum that is being checked for duplication is \n", csum)
2- I run a POST request, duplicate check fails


This was the JSON request:
{ "action": "addNote", "version": 6, "params": { "note": { "deckName": "Default", "modelName": "Basic", "fields": { "Front": "front content", "Back": "back content" }, "options": { "allowDuplicate": false, "duplicateScope": "all", "duplicateScopeOptions": { "deckName": null, "checkChildren": true, "checkAllModels": true } }, "tags": [ "airtable" ], "audio": [ { "url": "https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kanji=猫&kana=ねこ", "filename": "yomichan.mp3", "deleteExisting": false, "skipHash": "4ed622e5f01813a2d3a", "fields": ["Front"] } ] } } }
and this was the apiLog
3- Anki command line debug console
In the Anki command line debug console and here is the output I had from Step 1
:

the value that we are going to run a checksum on is
front content
the checksum that is being checked for is
3787401650
the value that we are going to run a checksum on is
front content
the checksum that is being checked for is
3787401650
4- here is what I had in my SQLite database:

The two notes (from step 2
POST request) in my SQLite database:
Note with ID
: 1662899404685
the front field
value: front content[sound:yomichan.mp3]
and its checksum
is 3144727897
Note with ID
: 1662899406766
the front field
value: front content[sound:yomichan.mp3]
and its checksum
is 3144727897
Summary of the problem
Anki-connect is building the search query on line 312 for duplication check with front field
value of front content
and its checksum is 3787401650
.
The previous note added is stored in the database has front field
value of front content[sound:yomichan.mp3]
and its checksum is: 3144727897
Yet, it's the same JSON POST request as you can see in the apiLog As a consequence, the duplication check fails.
Possible solution?
The search query on line 312 should look for front content[sound:yomichan.mp3]
and its checksum is: 3144727897
Therefore : the value of val = note.fields[0]
should take into consideration the mediafilename
attached to the field.