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

Duplicate check fails when media added to the Front Field #352

Open
SimbaNinja917 opened this issue Sep 11, 2022 · 1 comment
Open

Duplicate check fails when media added to the Front Field #352

SimbaNinja917 opened this issue Sep 11, 2022 · 1 comment

Comments

@SimbaNinja917
Copy link

SimbaNinja917 commented Sep 11, 2022

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.

@SimbaNinja917
Copy link
Author

SimbaNinja917 commented Sep 11, 2022

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

01

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

00b

00a

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 :

02a

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:

03

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
04

Therefore : the value of val = note.fields[0] should take into consideration the mediafilename attached to the field.

snoyes added a commit to snoyes/anki-connect that referenced this issue Sep 12, 2022
FooSoft added a commit that referenced this issue Sep 17, 2022
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

1 participant