Skip to content

[NRT-963] Skip auto-protect for notes on a non-AnkiHub note type - #1385

Merged
RisingOrange merged 2 commits into
mainfrom
NRT-963
Sep 29, 2026
Merged

RisingOrange merged 2 commits into
mainfrom
NRT-963

Conversation

@RisingOrange

@RisingOrange RisingOrange commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

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_protect returns early when the note's note type isn't an AnkiHub note type, the same check the rest of editor.py already makes.
  • Before this, the hook asked the AnkiHub DB for that note type's field names, got None, and raised TypeError: 'NoneType' object is not subscriptable.
  • The note stays linked to its AnkiHub deck after the user changes its note type, and a sync only switches it back when the server sends an update for that note, so the error could repeat on every edit.

How to reproduce

  1. Subscribe to an AnkiHub deck and sync.
  2. In the browser, select one of its notes and use Notes → Change Note Type to move it to a non-AnkiHub note type (e.g. a copy of the deck's note type).
  3. Open the note in the editor, edit a field and click out of it.
  4. Before: add-on error. After: no error, and no protection tag is added.

test_note_with_non_ankihub_note_type_not_protected covers 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:

  • Sync: only when the server sends an update for that note. If the user is logged into AnkiWeb, this shows the "Some changes require a full sync" dialog. The dialog lists the AnkiHub note type's name, so the cause isn't obvious. "Skip for now" abandons the whole deck update (and the remaining decks in that sync), and the dialog recurs on every sync.
  • Reset local changes: switches the note back without the full-sync warning.
  • Startup DB check: repairs by accident, if the note's last field is empty (e.g. an empty Back on Basic). It then prompts every startup to reset the whole deck.

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_id field, the note also drops out of the AnkiHub sidebar searches. Two more risks, from reading the code and not tested:

  • The switch back maps fields by position, not by name (change_note_types_of_notes in main/utils.py), so a protected field at a different position could end up in the wrong field.
  • After unsubscribing, a copied note type keeps its ankihub_id field.

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
RisingOrange marked this pull request as ready for review September 29, 2026 11:29
@RisingOrange
RisingOrange requested a review from a team September 29, 2026 11:29

@ddevdan ddevdan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RisingOrange
RisingOrange merged commit fc77a33 into main Sep 29, 2026
8 checks passed
@RisingOrange
RisingOrange deleted the NRT-963 branch September 29, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants