-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Export incomplete and import throws error #121
Comments
Thanks very much for reporting and sorry for the bug! I can indeed reproduce the issue. I believe I have a "palliative" fix for the issue (see below, section "Localised fix"). CausesI think I've found the source of the bug. The ultimate reason is that when Anki clones a note model (as when you go to The end result is that when you created the many nice note models, by cloning each other (as is the sensible route!), you ended up with many of the note models sharing the same Palliative solutionsVisual diagnosisIf you're interested you can see the UUIDs using Anki's debug console, which allows you to execute python code within Anki. If you press Ctrl+Shift+;, enter the following into the console (at the top) and press Ctrl+Enter: for m in map(lambda model: (model['crowdanki_uuid'], model['name']),
filter(lambda model: 'crowdanki_uuid' in model,
self.col.models.all())):
print(m) you'll see something like this('3d263d1c-b7ae-11ea-b976-40b076dccfad', 'prettyBasic')
('7012404a-fb4c-11ea-b291-40b076dccfad', 'prettyBook')
('3d2653d8-b7ae-11ea-b976-40b076dccfad', 'prettyCloze')
('3d263d1c-b7ae-11ea-b976-40b076dccfad', 'prettyConjugation')
('7012404a-fb4c-11ea-b291-40b076dccfad', 'prettyEvent')
('3d263d1c-b7ae-11ea-b976-40b076dccfad', 'prettyList')
('7012404a-fb4c-11ea-b291-40b076dccfad', 'prettyPerson')
('3d263d1c-b7ae-11ea-b976-40b076dccfad', 'prettyPoem')
('3d268c54-b7ae-11ea-b976-40b076dccfad', 'prettySentence')
('3d268c54-b7ae-11ea-b976-40b076dccfad', 'prettyWord') i.e. there are only four different UUIDs used by all the note types. Localised fixYou can also fix (i.e. disambiguate) the UUIDs using the console (again pasting into it), with the following code: fix_uuids_dict = {
# They're all being changed, though in principle one could keep four the way they were
'prettyBasic': '6cb207c7-22d9-4c24-a7ce-f06652ccb288',
'prettyCloze': '673ddbaf-13f2-46ef-a669-9a3637a52f26',
'prettyPerson': '97555342-72c0-4718-a14e-9ea53d01da84',
'prettyWord': 'd1049052-fc70-4c04-927b-5d65142cf7d8',
'prettyBook': '425f9772-6a2c-4912-a65b-f1e373fec4d0',
'prettyConjugation': '8f62895b-c508-4e8b-95d6-17fa64f7df03',
'prettyEvent': 'a3b68cea-479a-4538-9336-21288105bf43',
'prettyList': '9adc7a52-1c3a-473a-848d-b04509be9cbc',
'prettyPoem': '90a49382-4c6e-4ad9-854d-f2402978230e',
'prettySentence': '78f5753d-5bf5-4a67-978d-b40e649c7263'
}
for model in filter(lambda model: 'crowdanki_uuid' in model,
self.col.models.all()):
if model["name"] in fix_uuids_dict:
model["crowdanki_uuid"] = fix_uuids_dict[model["name"]]
self.col.models.save(model) This should work for you, for this particular deck, but obviously won't work in the general case. It also won't prevent new note models having duplicate UUIDs in the future (this needs to be fixed in CrowdAnki — see below). General diagnosisFor anybody else coming across this in the future, one can check whether one's Anki collection has note models with duplicated/colliding/repeated UUIDs with the following (again pasted into the console): repeated = {}
for model in filter(lambda model: 'crowdanki_uuid' in model,
self.col.models.all()):
cu = model["crowdanki_uuid"]
if cu in repeated:
repeated[cu] = True
else:
repeated[cu] = False
if any(repeated.values()):
print("WARNING! There are repeated Note Model uuids!")
else:
print("There are no repeated Note Model uuids! Everything is OK!") General (non-permanent) fixThe following code will set an alternative (automatically generated) uuid where there's a collision/repetition: from uuid import uuid1
uuids = []
for model in filter(lambda model: 'crowdanki_uuid' in model,
sorted(self.col.models.all(), key=lambda m: m["id"])):
# we're sorting in the hope that note models with higher ids (which mostly corresponds to creation date) were created later, so we change the uuid of the copies, not the original
cu = model["crowdanki_uuid"]
if cu in uuids:
print("Replacing UUID for note model " + model["name"] + "!")
model["crowdanki_uuid"] = str(uuid1())
self.col.models.save(model)
else:
uuids.append(cu) (Since the UUIDs are generated automatically, this might not be ideal in the case of notes shared by multiple people, if several people use this at the same time on their copies of the same deck, but it shouldn't cause any major issue.) By "non-permanent" I mean that this will need to be re-run every time a new note model is created by duplicating a note model which already has a Tackling the root causesWhenever a note model is cloned, we'd ideally want The code for cloning note models is in An alternative would be to check for uniqueness of note model UUIDs whenever we carry out any operation (import, export, snapshot), and if there are any collisions, change the UUID of the note models with the higher (I'll think about how best to deal with this, when I have more time.) BTW thanks for the nice-looking and detailed note models! |
Thanks a lot for the quick and detailed response! I was able to verify that this was indeed the cause for my problem, and the fix worked fine as well, so thank you very much. I'll leave this issue open to track progress on the root cause, hopefully you're able to find a clean solution. |
I'm glad that the "palliative" fix worked! |
I'm trying to export my deck containing card templates, the json is incomplete, there's only 3 of the 11 note types.
When trying to import from this json, I get this error:
To try to reproduce, here is the deck on AnkiWeb.
The text was updated successfully, but these errors were encountered: