mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
make sure we update guid in note object too
This commit is contained in:
parent
bd1c6d4395
commit
29e93f8c1d
4 changed files with 24 additions and 5 deletions
|
@ -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:
|
||||
|
|
BIN
tests/support/diffmodels2-1.apkg
Normal file
BIN
tests/support/diffmodels2-1.apkg
Normal file
Binary file not shown.
BIN
tests/support/diffmodels2-2.apkg
Normal file
BIN
tests/support/diffmodels2-2.apkg
Normal file
Binary file not shown.
|
@ -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"))
|
||||
|
|
Loading…
Reference in a new issue