Moving existing AnKing card into new AnkiHub deck - potential syncing conflict?

Hello,

I hope you can help me out with a particular problem I foresee arising. I had someone recently submit a few new notes to my deck which I’ve been maintaining (deck ID: 5a1160ef-6f41-4d8c-948b-f72275ef0ff7). I wasn’t aware before I approved the new notes that they were notes derived from an earlier non-AnkiHub linked version of the AnKing deck (v9). Instead of copying them, the person had simply moved them to my deck which they had subscribed to (rather than properly duplicating them which creates new note IDs using the right click > create copy function), converted them to my deck’s cardstyle and submitted them as new cards in my deck. Given that I have the AnKing deck on my computer, when I synced the changes with AnkiHub, the cards remained in the original AnKing deck even though they were tagged within my deck’s tagging structure. I strongly suspect this is because the Anki ID is unique to the AnKing cards so when I synced with AnkiHub the cards were recognised. I can move them to my deck and sync them as normal, but this essentially removes the cards from the AnKing deck.

My question is therefore - what is the current workaround to prevent syncing conflicts should someone have two AnkiHub deck subscriptions with the same card in both decks - say both with my deck and the AnKing deck whereby both AnkiHub decks have the same cards with the same AnkiHub ID? I checked on AnkiHub on both decks and they do indeed both have the same Anki ID despite different cardstyles. I haven’t been game enough yet to test it out in case (I’ve only subscribed to my own deck on AnkiHub and kept the AnKing deck unlinked with AnkiHub) it causes serious problems and corrupts the files. Given AnkiHub is linked to the note ID, I’m curious whether synced changes from both decks would lead to problems (would there be overwrite conflicts etc.)?

Seeing as the ā€œdelete notesā€ feature is not yet enabled in AnkiHub, I can’t really get rid of the cards either to prevent conflicts either. And even if I do tag them for deletion, people with the AnKing deck will have those cards permanently deleted if they did delete them (rather than delete it just from my deck which is the ideal situation). I ideally want it to be that people can subscribe to both decks and have all the cards entirely separate.

The note IDs with potential conflicts:

  • 1484862446206
  • 1484862452178
  • 1484862461322
  • 1484862490045
  • 1484862498158

Hope you guys can help me! :slight_smile:

Stapedius

1 Like

Would like to bump this :))

1 Like

If we just delete those notes for you on the backend would that solve your problem?

The AnkiHub note that will be synced depends on the order in which the user subscribes to the decks with duplicate notes. However, the note will be updated in place (whichever deck it is already located in). So if someone is subscribed to the AnKing Overhaul deck and then they subscribe to yours, AnkiHub will skip the duplicates from your deck.

@jakub.f , can you do a quick write-up about this behavior in our documentation and link to it here?

1 Like

I think that this issue is covered in this post:

3 Likes

If this is possible that would be great! I would prefer to keep all AnKing Overhaul cards out of my deck for the moment (even though from what I understand from the replies it wouldn’t really matter as long as the duplicated cards are in the different deck).

1 Like

I see. Thanks for linking that. I did see that section appear on the notion documentation last week but I was still a bit confused on what it meant. This write up makes it a lot clearer. :slight_smile:

1 Like

I deleted them for you.

2 Likes

Hey @andrewsanchez crazy to think it’s been 3 years since I posted this, but I do actually have a question regarding this thread! Despite having deleted the above listed notes 3 years ago on the backend well before delete notes was enabled (all 6 of them), and repeatedly deleting them locally on my deck, it seems there appears to be a bug somewhere where those deleted notes on the backend haven’t really been deleted. Every now and then they slip back into my deck and I can’t really actually delete. When I try to click on the linked AnkiHub link it says the page does not exist.

I’m wondering if deleting them on the backend has put these cards into some weird phantom state where they appear when a sync is made. Is there any way to remedy this?

Kind regards,

Stapedius

These note IDs are not in any of the decks you are currently subscribed to.

This could happen if you were subscribed to the Step Deck. Were you? I see you are not right now. if you were, it seems this could happen:

  1. Stapedius is subscribed to both the AnKing Step Deck and the Malleus deck
  2. The AnKing deck has these 5 anki_ids as active, living notes
  3. When the addon syncs the AnKing deck, it downloads these notes and creates/updates them locally in Anki
  4. The addon’s conflict detection only skips notes if an active (non-deleted) entry for that anki_id exists in a different deck’s local DB entry. Since the Malleus deck entries were deleted, there’s no conflict and the notes flow in from AnKing as expected
  5. Stapedius likely sees these notes reappearing locally and thinks the Malleus deck is the source, but it’s actually the AnKing sync putting them back

Another possibility: when we ā€œhard deletedā€ those notes for you, it broke the add-ons’ ability to clear them for you locally since it relies on our server sending this information in the sync response. So the add-on had no way to know those should be deleted. So they could persist in the local AnkiHub DB forever, orphaned.

Do you know if this is impacting other users?

The Reset all local changes to a deck action (from the AnkiHub browser menu) could be the culprit.

If you use the Upload logs and data from our help menu, I can take a look. You can also run this in the debug console script. Try running it after you delete those notes from your collection

# Paste into Anki Debug Console (Ctrl+Shift+;)
# Read-only diagnostic — does NOT modify anything.

import sqlite3, os
from pathlib import Path

ANKI_NIDS = [1484862446206, 1484862452178, 1484862461322, 1484862490045, 1484862498158]
nids_str = ",".join(str(n) for n in ANKI_NIDS)

# Find the AnkiHub DB
anki_base = Path(mw.pm._default_base())
ankihub_base = Path(os.getenv("ANKIHUB_BASE_PATH")) if os.getenv("ANKIHUB_BASE_PATH") else anki_base.parent / "AnkiHub"
print(f"AnkiHub base: {ankihub_base}")

# Find the DB file in any profile subfolder
db_files = list(ankihub_base.glob("*/ankihub.db"))
print(f"Found {len(db_files)} DB file(s): {db_files}")

for ah_db_path in db_files:
    print(f"\n=== AnkiHub Local DB: {ah_db_path} ===")
    conn = sqlite3.connect(str(ah_db_path))
    rows = conn.execute(
        f"SELECT anki_note_id, ankihub_note_id, ankihub_deck_id, last_update_type "
        f"FROM notes WHERE anki_note_id IN ({nids_str})"
    ).fetchall()
    conn.close()
    print(f"Found {len(rows)} of {len(ANKI_NIDS)} notes")
    for r in rows:
        print(f"  anki_nid={r[0]} ah_nid={r[1]} deck={r[2]} update_type={r[3]}")

# Check Anki collection
print("\n=== Anki Collection ===")
existing = mw.col.db.list(f"SELECT id FROM notes WHERE id IN ({nids_str})")
print(f"Found {len(existing)} of {len(ANKI_NIDS)} notes")
for nid in existing:
    note = mw.col.get_note(nid)
    fields = {f["name"]: note.fields[i] for i, f in enumerate(note.note_type()["flds"])}
    ah_id = fields.get("ankihub_id", "FIELD_NOT_FOUND")
    has_deleted_tag = "AnkiHub_Deleted" in note.tags
    print(f"  nid={nid} ankihub_id='{ah_id}' has_deleted_tag={has_deleted_tag}")

print("\nDone. No changes were made.")

I also think the following would work:

  • add these notes back to your deck (submit new note suggestions)
  • Delete them (submit delete note suggestions)
  • they would then be removed for you and all subscribers on the next sync

Keep in mind this option in the deck management screen:

Thanks @andrewsanchez and sorry for my late reply. I can’t remember ever subscribing to the AnKing step decks but I may have at one point. From memory these cards were submitted by another contributor to the deck who submitted them without duplicating the cards appropriately so the card IDs were the same as the AnKing ones. I think they were inadvertently approved. I’ve asked around and it sounds like it is just me that has this issue.

So far I’ve tried:

  • Reset all local changes to a deck –> nil fix
  • Deleting the cards locally –> initially appeared to work, but weirdly after ~2 days I noticed they reappeared in my deck. It’s very weird because I tried syncing with AnkiHub after deleting them and they did not reappear. I think this has been intermittently occurring as I have deleted them repeatedly over the past 2 years, which makes me think they are still somehow related to the AnkiHub sync. I am also not subscribed to the AnKing decks so unclear how they are reappearing. It’s also strange because the appearance of the cards are as they were when they were in the Malleus deck with Malleus-specific tags (not the AnKing ones). Also, they must be syncing from the AnkiHub database as they now conform to the new notetype field changes that we have in the deck (without the since deleted First Aid and AMBOSS fields).
  • I cannot add the notes back into the deck or delete them via AnkiHub –> error message ā€œno changes. Try syncing with AnkiHub firstā€.

I also tried to use the debug script within Anki after deleting them locally but it didn’t seem to suggest any errors for me but perhaps I was using it wrong. For what it’s worth I used the ā€œUpload logs and dataā€ feature so you should have my logs there to examine (ankihub_addon_debug_info_Stapedius_1774998962.zip).

Thanks for your help, this one’s a bit of a mystery!

  • Stapedius