Avoid duplicating crowdanki_uuid when cloning note model #136
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix #121, fix #123.
Testing
test
) with at least one note of note type (say)Basic
.test
with CrowdAnki.Basic
note type has been correctly exported, and that in total, one note type has been exported (e.g. usejq < deck.json '.note_models | length'
).)Tools
>Manage note types
>Add
>Clone: Basic
>OK
), say calledBasic_test
.test
deck create a note of typeBasic_test
.deck.json
. (e.g. withjq < deck.json '.note_models | length'
)Expected result (and the result with this PR)
Actual result (before this PR)
Alternatively, inspect the note models with a debug console script:
Limitations
AnkiDroid and AnkiMobile
Unfortunately, this PR does not prevent a user from duplicating a note model's crowdanki_uuid when cloning a note model on AnkiDroid or AnkiMobile. Hopefully most users create new note models on desktop!
Add-ons that clone note models
As described in the relevant docstring, if an add-on clones a note-model with
add=True
, then (on Anki ≥ 2.1.45) we won't catch the duplicated UUID. (This could be dealt with relatively easily.)(Looking quickly, it seems that there are cases of add-ons cloning note models:
https://github.com/search?q=models.copy+anki&type=Code )
Future work
(This is for my own reference, and for informational purposes.)
Checking for duplicate
crowdanki_uuid
s during exportIt might be worth adding code that checks for duplicate
crowdanki_uuid
s when exporting, in order to deal with the already duplicatedcrowdanki_uuid
s in users' databases and those that will be duplicated in the future when duplicating note models on AnkiDroid and AnkiMobile (as described above). However, that is likely far more complicated to do correctly (how do we determine which is the original note model and which the new one?), so I'll leave it for a future refinement.Debug console script
Also, like mentioned in #135, I'll try to write (ASAP) a debug console script for diagnosing and fixing all the recent
crowdanki_uuid
issues.(Alternatively, should we have a menu-item, similar to the built-in
Tools > Check database
for checking the UUID issues?)Checking for issues during import
As discussed in #121 and #123, the duplicate
crowdanki_uuid
s issue leads to incomplete exports of note models. (CrowdAnki
thinks that several different note models are the same, so exports only one of them.) This can be particularly problematic during import if the number of fields of a note doesn't match the number of fields in the (incorrect) note type.It might be nice to check, during import, that the number of fields in a note matches the number of fields in the note type.
Creating a hook
I'll ask upstream (in Anki) whether we could have a hook that runs just before or just after a note model was duplicated (similar to
deck_conf_did_add_config
), in order that we can remove the monkey patching here!