[NRT-963] Skip auto-protect for notes on a non-AnkiHub note type - #1385
Merged
Merged
Conversation
Users can switch an AnkiHub note to one of their own note types, and a sync only switches it back when the server updates that note. The auto-protect field-unfocus hook then looked up field names for a note type the AnkiHub DB doesn't have, got None and raised a TypeError on every field edit. Fixes ANKIHUB_ADDON-14BQ
RisingOrange
marked this pull request as ready for review
September 29, 2026 11:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Users get an add-on error when they click out of a field in the note editor on an AnkiHub note that has been switched to one of their own note types. The auto-protect hook now skips those notes.
Related issues
Proposed changes
_on_field_unfocus_auto_protectreturns early when the note's note type isn't an AnkiHub note type, the same check the rest ofeditor.pyalready makes.None, and raisedTypeError: 'NoneType' object is not subscriptable.How to reproduce
test_note_with_non_ankihub_note_type_not_protectedcovers this; it fails with the Sentry error without the fix.Screenshots and videos
N/A
Further comments
An alternative was to compare against the AnkiHub note type's field names instead, but the local note type's fields may not match them, so skipping is the safer behavior until the next sync that updates the note switches it back.
Broader issue (not addressed here)
This PR only stops the crash. AnkiHub notes that users switch to their own note type are a wider problem. The add-on doesn't prevent or warn about it, and it only switches the note back to its AnkiHub note type when an import includes that note:
While a note is on the other type, the editor's AnkiHub buttons and suggestions are disabled for it. If the new type has no
ankihub_idfield, the note also drops out of the AnkiHub sidebar searches. Two more risks, from reading the code and not tested:change_note_types_of_notesinmain/utils.py), so a protected field at a different position could end up in the wrong field.ankihub_idfield.