Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin overwrites decks after manual edits in Anki #6

Closed
sdnnvs opened this issue Aug 8, 2024 · 3 comments
Closed

Plugin overwrites decks after manual edits in Anki #6

sdnnvs opened this issue Aug 8, 2024 · 3 comments
Assignees
Labels
invalid This doesn't seem right

Comments

@sdnnvs
Copy link

sdnnvs commented Aug 8, 2024

Luckily, I used an empty deck for testing. The disaster could have been huge.

Despite the plugin instructions stating that the complex deck structure of the monitored folder works, it doesn't. All subdecks are created in the vault without any hierarchy.

The procedure was as follows:

  1. In Obsidian, I created the folder monitored by the plugin called "Flashcards".
  2. Created the "Subdeck" folder inside the "Flashcards" folder.
  3. Sync
  4. In Anki, Subdeck is created as a deck and not a subdeck of Flashcard.
  5. In Anki, I move Subdeck inside the Flashcard deck. Now we have Flashcard::Subdeck.
  6. In Obsidian, Sync.
  7. In Anki, Subdeck becomes a deck again and the Flashcard deck is deleted with all its cards!!!

In summary, we have two problems:

  1. complex decks in Obsidian are not being mirrored in Anki during synchronization;
  2. when we move a deck to become a subdeck, with subsequent synchronization, the subdeck turns into a deck again and the deck that supported it is deleted.
@sdnnvs sdnnvs changed the title Plugin apaga decks no Anki Plugin deletes decks in Anki Aug 8, 2024
@kitschpatrol
Copy link
Owner

kitschpatrol commented Aug 8, 2024

Hi, thanks for reporting this and I can see why the mapping of synced folders in Obsidian to Anki decks might be confusing.

However, for now this is all working as designed and documented.

First point — and this one might be worth changing:

Decks are created, as needed, if there is a note to contain in a given hierarchy.

Currently, syncing /Flashcards with this folder structure:

📁 Flashcards
└── 📁 Subdeck
   ├── 📝 Note A.md
   └── 📝 Note B.md

Will yield the following deck in Anki, because /Flashcards does not contain multiple items:

Subdeck

If you add a second folder to /Flashcards, you still won't get a Flashcards deck since it doesn't contain any notes directly. E.g.,

📁 Flashcards
├── 📁 Subdeck
│  ├── 📝 Note 1.md
│  └── 📝 Note 2.md
└── 📁 Subdeck B
   ├── 📝 Note 1.md
   └── 📝 Note 2.md

Yields the following decks in Anki:

Subdeck
Subdeck B

If you then add a note to the root of Flashcards, you'll get the full hierarchy:

📁 Flashcards
├── 📝 Note 1.md
├── 📁 Subdeck
│  ├── 📝 Note 1.md
│  └── 📝 Note 2.md
└── 📁 Subdeck B
   ├── 📝 Note 1.md
   └── 📝 Note 2.md

Yields:

Flashcards
Flashcards::Subdeck
Flashcards::Subdeck B

The idea here is that you can sync a folder of folders in Obsidian, without necessarily including top-level folder as a deck. In my case I have an /Anki folder in the root of my Obsidian vault that I sync, but I don't want all of my synced cards to be inside an Anki deck.

(And there's additional logic on top of that do deal with multiple nested "empty" folders, etc...)

But I can see how automatically pruning the hierarchy can be unexpected.

I'll weigh changing this behavior and post to this issue thread when a change (or a decision to leave as-is) is made.


Second point, and this is not subject to change:

Your markdown notes and their hierarchy are the single point of truth.

This is why editing Yanki-generated cards or decks in Anki is not recommended or supported.

You described doing exactly this in your summary when you moved the subdeck in Anki in your step 5. When you synced again, Anki saw that some of the notes it had previously created were now in the "wrong" deck according to the logic outline above, and moved them accordingly to match the hierarchy of your synced folder.

Even if you disagree with how it maps folder hierarchy to deck hierarchy, there's no reason for a deterministic system's actions to change across invocations on that basis alone. 😁

Also regarding a potential "huge disaster", it's worth noting that any cards Anki had not previously created / synced were never at risk, since Yanki only ever acts on Anki notes that it has previously created with a specific note type, namespace field, and namespace value.

@kitschpatrol kitschpatrol changed the title Plugin deletes decks in Anki Plugin overwrites decks after manual edits in Anki Aug 8, 2024
@kitschpatrol
Copy link
Owner

kitschpatrol commented Aug 8, 2024

I'm editing the issue title to make it clear that this behavior is not happening spontaneously, since it's happening after manual changes are made to Yanki-generated cards in Anki, as advised against in the documentation.

@kitschpatrol kitschpatrol self-assigned this Aug 8, 2024
@kitschpatrol kitschpatrol added the invalid This doesn't seem right label Sep 1, 2024
@kitschpatrol kitschpatrol added bug Something isn't working invalid This doesn't seem right and removed invalid This doesn't seem right bug Something isn't working labels Sep 2, 2024
@kitschpatrol
Copy link
Owner

I've added some documentation to the readme explaining the logic around how folders and notes are mapped to deck.

There also was one data losing bug that has been identified and fixed in issue #14 , which is possibly related to what you originally reported.

If you run into anything similar in the future and would like support, please open a new issue with a minimal sample vault and steps to reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants