diff --git a/anki/importing/anki2.py b/anki/importing/anki2.py index 7ccd8835b..18c6fad6d 100644 --- a/anki/importing/anki2.py +++ b/anki/importing/anki2.py @@ -97,9 +97,10 @@ class Anki2Importer(Importer): note = list(note) guid, mid = note[1:3] duplicate = False - guidChange = False + first = True # do we have the same guid? if guid in self._notes: + first = False # and do they share the same model id? if self._notes[guid][2] == mid: # and do they share the same schema? @@ -109,9 +110,6 @@ class Anki2Importer(Importer): self.src.models.scmhash(dstM)): # then it's safe to treat as a duplicate duplicate = True - if not duplicate: - # not identical models, so we need to change guid - guidChange = True # missing from local col or divergent model? if not duplicate: # get corresponding local model @@ -129,8 +127,9 @@ class Anki2Importer(Importer): dirty.append(note[0]) # if it was originally the same as a note in this deck but the # models have diverged, we need to change the guid - if guidChange: + if not first: guid = guid64() + note[1] = guid # note we have the added note self._notes[guid] = (note[0], note[3], note[2]) else: diff --git a/tests/support/diffmodels2-1.apkg b/tests/support/diffmodels2-1.apkg new file mode 100644 index 000000000..e3c85af81 Binary files /dev/null and b/tests/support/diffmodels2-1.apkg differ diff --git a/tests/support/diffmodels2-2.apkg b/tests/support/diffmodels2-2.apkg new file mode 100644 index 000000000..06534f446 Binary files /dev/null and b/tests/support/diffmodels2-2.apkg differ diff --git a/tests/test_importing.py b/tests/test_importing.py index 023996b3f..d06dc5aad 100644 --- a/tests/test_importing.py +++ b/tests/test_importing.py @@ -158,6 +158,26 @@ def test_anki1_diffmodels(): # as the model schemas differ, should have been imported as new model assert after == before + 1 +def test_anki2_diffmodels(): + # create a new empty deck + dst = getEmptyDeck() + # import the 1 card version of the model + tmp = getUpgradeDeckPath("diffmodels2-1.apkg") + imp = AnkiPackageImporter(dst, tmp) + imp.run() + before = dst.noteCount() + # repeating the process should do nothing + imp = AnkiPackageImporter(dst, tmp) + imp.run() + assert before == dst.noteCount() + # then the 2 card version + tmp = getUpgradeDeckPath("diffmodels2-2.apkg") + imp = AnkiPackageImporter(dst, tmp) + imp.run() + after = dst.noteCount() + # as the model schemas differ, should have been imported as new model + assert after == before + 1 + def test_csv(): deck = getEmptyDeck() file = unicode(os.path.join(testDir, "support/text-2fields.txt"))