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

Cant import from github #106

Closed
joecabezas opened this issue Oct 28, 2020 · 6 comments · Fixed by #127
Closed

Cant import from github #106

joecabezas opened this issue Oct 28, 2020 · 6 comments · Fixed by #127

Comments

@joecabezas
Copy link

joecabezas commented Oct 28, 2020

Hello!, I cant import the deck I last used 10 months ago (jan2020)

here is the repo:
https://github.com/joecabezas/k014_anki_deck_00_99_major_system_pegs

I just modified the repo so there is a single json with the same name of the repo (expecting this to fix my issue but not)

Anki version: 2.1.35 (latest)

repro steps:

it shows error:

Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue on the add-on support site.
Debug info:
Anki 2.1.35 (84dcaa86) Python 3.8.0 Qt 5.14.2 PyQt 5.14.2
Platform: Windows 10
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2020-10-27 23:27:33

Caught exception:
Traceback (most recent call last):
  File "C:\Users\Joe\AppData\Roaming\Anki2\addons21\1788670778\anki\ui\action_vendor.py", line 35, in <lambda>
    lambda: GitImporter.on_git_import_action(self.window.col))
  File "C:\Users\Joe\AppData\Roaming\Anki2\addons21\1788670778\github\github_importer.py", line 28, in on_git_import_action
    GitImporter(collection).import_from_git()
  File "C:\Users\Joe\AppData\Roaming\Anki2\addons21\1788670778\github\github_importer.py", line 33, in import_from_git
    self.clone_repository_and_import(repo_url)
  File "C:\Users\Joe\AppData\Roaming\Anki2\addons21\1788670778\github\github_importer.py", line 48, in clone_repository_and_import
    AnkiJsonImporter.import_deck_from_path(self.collection, repo_local_path)
  File "C:\Users\Joe\AppData\Roaming\Anki2\addons21\1788670778\importer\anki_importer.py", line 101, in import_deck_from_path
    if importer.load_deck(directory_path):
  File "C:\Users\Joe\AppData\Roaming\Anki2\addons21\1788670778\importer\anki_importer.py", line 39, in load_deck
    deck.save_to_collection(self.collection, import_config=import_config)
  File "C:\Users\Joe\AppData\Roaming\Anki2\addons21\1788670778\representation\deck.py", line 131, in save_to_collection
    self.save_decks_and_notes(collection=collection,
  File "C:\Users\Joe\AppData\Roaming\Anki2\addons21\1788670778\representation\deck.py", line 144, in save_decks_and_notes
    full_name = self._save_deck(collection, parent_name)
  File "C:\Users\Joe\AppData\Roaming\Anki2\addons21\1788670778\representation\deck.py", line 173, in _save_deck
    self.anki_dict["conf"] = self.metadata.deck_configs[self.deck_config_uuid].anki_dict["id"]
KeyError: '8cc79fcf-35d9-11ea-9a85-305a3a05e8e9'

I tried downgrading to 2.1.26 as stated in #96
Also tested with Anki 2.1.25, Anki 2.1.15 with no luck

I cant make it to work again, I want to at least recover the deck, which is a single one, what I am missing?

-Joe

@joecabezas
Copy link
Author

after closing error I can see deck imported with no cards

@aplaice
Copy link
Collaborator

aplaice commented Oct 28, 2020

I can reproduce the error. I'll try to fix it asap.

(Sorry for the issue and thanks for reporting!)

@joecabezas
Copy link
Author

That was blazing fast, thanks! :3

@aplaice
Copy link
Collaborator

aplaice commented Oct 28, 2020

I think that this is likely an issue with CrowdAnki's export.

I think that in your k014_anki_deck_00_99_major_system_pegs.json you need to change either the deck_config_uuid or the crowdanki_uuid in deck_configurations so that the two are the same. For instance, you could have them both be 8cc79fcf-35d9-11ea-9a85-305a3a05e8e9:

{
    "__type__": "Deck",
    "children": [],
    "crowdanki_uuid": "8cc79fce-35d9-11ea-bf79-305a3a05e8e9",
    "deck_config_uuid": "8cc79fcf-35d9-11ea-9a85-305a3a05e8e9",
    "deck_configurations": [
        {
            "__type__": "DeckConfig",
            "autoplay": true,
            "crowdanki_uuid": "8cc79fcf-35d9-11ea-9a85-305a3a05e8e9",

(I've tested this, and it allows import to proceed correctly, at least for me.)

AFAICT the problem is caused by the fact that currently, the deck json specifies uuid:8cc79fcf-35d9-11ea-9a85-305a3a05e8e9 as the deck configuration to be used, but no deck configuration with that uuid is "provided" by the deck json (deck_configurations's value is a list of the deck configurations that it provides) and that deck configuration also isn't "available" in your fresh Anki install*.

* when you were originally editing the deck, then that deck configuration must have been available in Anki, (though for some reason it wasn't exported by CrowdAnki), so you wouldn't have encountered the issue at the time.


I'll try to dig into how/under what circumstances CrowdAnki doesn't export the currently used deck configuration, but that's not directly relevant to your problem, now. :)


(FWIW downgrading to 2.1.26 and the associated version of CrowdAnki (using the CrowdAnki from git — it's not possible from AnkiWeb atm) does not solve the problem, without modifying the deck itself, so this issue isn't a regression.)

@joecabezas
Copy link
Author

I changed the UUID and now works, for posterity here is the commit ID that caused the problem in my deck before fixing it
https://github.com/joecabezas/k014_anki_deck_00_99_major_system_pegs/tree/86470a98b427f3cef91d490f350a3d78230ef753

now I will update master to a working version of my deck. thanks!

@aplaice
Copy link
Collaborator

aplaice commented Nov 6, 2020

I'm glad that the solution worked! Also, thanks for pinpointing the commit that introduced the issue — it seems to be consistent with what I found.


The general issue

I can reproduce the export problem.

  1. Import this deck with CrowdAnki. (It's a trivial, basic deck — you could equally well create your own, but currently the setting of deck_config_uuid is broken when exporting a fresh deck (the deck_config_uuid is set in the CrowdAnki export, but isn't set within Anki), which could confound investigating the issue (edit: that issue is now fixed!).)

CrowdAnki: Import git repository > https://github.com/aplaice/crowdanki_deck_config_export_test.

  1. Change the deck's options group, say to Default.

  2. Export the deck with CrowdAnki.

  3. Import the exported deck with CrowdAnki. (CrowdAnki: Import from disk)

(Interestingly, it's not even necessary to start a fresh profile before 4! This is presumably because in crowd-anki/representation/deck.py:173, we only care about the deck configs present in the CrowdAnki JSON.)


AFAICT the issue is that when the deck options group is changed for the deck, in Anki, then the "deck's conf" is updated to the id of the newly set options group (so Anki knows that the change has been made), but the "deck's deck_config_uuid" is not changed to the option group's crowdanki_uuid (so CrowdAnki doesn't know).

(In terms of underlying the database, at least in Anki 2.1.26, the JSON object in the decks column in the col table is updated such that the conf for the given deck is changed, but the deck_config_uuid is not. For Anki 2.1.35, there are more opaque blobs in the database, so it's harder to reason about, but the relevant information is in the decks table. The conf id seems to be encoded within the kind column. I briefly tried to work out the encoding scheme by looking at the relevant code, but my Rust is currently non-existent.)

I haven't looked at the code in detail, yet, (I had been postponing posting this until I did, but didn't get around to it), but it seems that we have three options:

  1. Use the deck_conf_will_save_config hook to update deck_config_uuid whenever the config is changed.

  2. Stop explicitly storing the deck_config_uuid with the deck, and only recover it via the deck's conf and the corresponding config's crowdanki_uuid, whenever needed.

  3. Update deck_config_uuid (via conf and the corresponding crowdanki_uuid) whenever it's actually needed. (i.e. 2 with back-up).

All three are probably brittle in their own ways.

aplaice added a commit to aplaice/CrowdAnki that referenced this issue Apr 27, 2021
We don't want the deck_config_uuid to be imported into the database,
since it duplicates the information stored in the deck's `conf` and in
the relevant deck config's `crowdanki_uuid`, but isn't updated when
`conf` changes, resulting in potentially broken `deck.json`s on
export.

See Stvad#106, Stvad#116.
aplaice added a commit to aplaice/CrowdAnki that referenced this issue Jun 5, 2021
We don't want the deck_config_uuid to be imported into the database,
since it duplicates the information stored in the deck's `conf` and in
the relevant deck config's `crowdanki_uuid`, but isn't updated when
`conf` changes, resulting in potentially broken `deck.json`s on
export.

See Stvad#106, Stvad#116.
aplaice added a commit to aplaice/CrowdAnki that referenced this issue Aug 9, 2021
We don't want the deck_config_uuid to be imported into the database,
since it duplicates the information stored in the deck's `conf` and in
the relevant deck config's `crowdanki_uuid`, but isn't updated when
`conf` changes, resulting in potentially broken `deck.json`s on
export.

See Stvad#106, Stvad#116.
southzyzy added a commit to southzyzy/crowdanki-test that referenced this issue Jan 22, 2025
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 a pull request may close this issue.

2 participants