Skip to content

Workarounds — Duplicate note model uuids

aplaice edited this page Dec 5, 2021 · 2 revisions

Due to a bug in the interaction between CrowdAnki and Anki, when a note model (aka note type) with an already assigned crowdanki_uuid, was duplicated, its clone inherited its crowdanki_uuid. This, in turn, meant that when a deck containing both the original note model and its clone was exported, only one of the note models was included in the export. This lead to many problems (e.g. #121, #123, #134).

Scope

This bug was present up to and including v0.9.

The bug is mostly fixed in master (see #136) and will be fixed in v0.9.1.

Diagnosis

Using the following script for the Anki debug console you can check whether you're affected (whether any of your crowdanki_uuids are duplicated).

Debug console script
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!")

Debug console script fix

Using the following script for the Anki debug console you can disambiguate the currently duplicated crowdanki_uuids. Note that unless you're using the latest version of CrowdAnki (v0.9.1 or later), this won't prevent the crowdanki_uuid from being duplicated when you create a new note model via cloning.

Debug console script
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)