Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cause Duplicates #32

Open
namurai21 opened this issue Mar 23, 2020 · 7 comments
Open

Update Cause Duplicates #32

namurai21 opened this issue Mar 23, 2020 · 7 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@namurai21
Copy link

The "col.notes.update()" seems to duplicates cards when editing values in "nflds". E.g. two exact "Card 1" from same Note (nid).

@klieret klieret added the bug Something isn't working label Mar 23, 2020
@klieret
Copy link
Owner

klieret commented Mar 23, 2020

Hi @namurai21. Thanks a lot for reporting this. Could you offer some more details of how to reproduce this issue? E.g. a small code snippet that demonstrates this, etc.

Quite busy at the moment, so this would help me to figure this out faster.

@namurai21
Copy link
Author

namurai21 commented Mar 24, 2020

Thanks for the response @klieret. Here is a modified snippet of my code:

New_notes = [['lexeme', 'new example sentence 1', 'new example sentence 2' , so on..]]
col = Collection(anki_path, user=user_name)
ntcol = col.notes.copy()
ntcol = ntcol.loc[(ntcol['nmodel'] == "NoteEnglish")]

ntcol.fields_as_columns(inplace=True)

for each_note in new_notes:
	lex = each_note[0] # The top Field
	sens = [1:] #I use separate function to produce list of tuples like "[('nfld_SEN1', 'new example setence 1')...]

	for sen in sens:
		nid = ntcol.loc[ntcol["nfld_LEX"] == lex].index.tolist()[0]
		ntcol.loc[nid, sen[0]] = sen[1]

ntcol.fields_as_list(inplace=True)
col.notes.update(ntcol)
col.summarize_changes()`
col.write(modify=True, delete=False)

The "summarize_changes" and "was_modified" both show the correct update, and the changes do seem to work initially when logging back in Anki (the fields are updated accordingly with new values). However, the updated notes soon duplicate the cards for each updated field, e.g. two identical "Card 4" cards. I use Conditional Replacement for Card Generation for these cards, and duplicates only occur for cards that were previously empty (therefore cards non-existent) before updates made via Ankipandas. I suspect this is the reason for this result.

Finally, I'm still a novice in dealing with dataframes, and I apologize in advance for any simple mistake.
And, thank you very much for creating this tool. Super useful. Thank you.

@klieret
Copy link
Owner

klieret commented Apr 5, 2020

Thanks for the code snippet! I was a bit too busy to look at this so far; I'll definitely have a look at it this week. Sorry for being slow!

@klieret
Copy link
Owner

klieret commented Apr 10, 2020

Okay, I just looked at the code snippet. Let me summarize what I understood you're trying to do

  1. You have an Anki collection that already contains notes, containing a field LEX and, say sentence
  2. Some of the notes would produce empty cards.
  3. Anki doesn't produce any cards for these notes
  4. You want to update these notes
  5. You have tuples (LEX, sentence) that you want to use to update these notes
  6. For each of these tuples, you search for the corresponding note and update the sentence column
  7. AnkiPandas sumarize_changes looks ok and only shows updated notes
  8. Upon starting Anki, the notes that produced empty cards before hand now produce more than one Card

When you go in Anki's browser, what does it say for the card types of the duplicated cards?

You might also look into this by right-clicking the card and selecting card info, this should also give you IDs for the note and the card.

@namurai21
Copy link
Author

Your summary is exactly what I meant. Thank you.

I have tried my script after the recent upgrade, and it seems that the problem has been resolved! The changes made in "nflds" successfully creates/deletes cards (reflective of Selective Card Generation) without any duplicates. It may have been a mistake in my code, but nonetheless, thank you, again.

Therefore, it may now be irrelevant, but to answer your question, the duplicates did have the same ID, Note ID, and Card Type.
Sorry for the late response.

@namurai21
Copy link
Author

namurai21 commented May 11, 2020

The problem persists.
The same duplicates are created as soon as I edit any of the contents in the field.

@klieret klieret added the help wanted Extra attention is needed label Sep 27, 2020
@klieret
Copy link
Owner

klieret commented Sep 27, 2020

Sorry for not giving any updates on this, I'm currently too busy. I hope I will get to this eventually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants