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

Bug: Fail on import #14

Open
hundredpinbowling opened this issue Jan 28, 2025 · 3 comments
Open

Bug: Fail on import #14

hundredpinbowling opened this issue Jan 28, 2025 · 3 comments

Comments

@hundredpinbowling
Copy link

  1. OS: Fedora 41 GNU/Linux
  2. Anki version: 24.11 from Flatpak

Cropro fails when trying to import large amounts of cards from another profile. It works when selecting only a few cards, but when select thousands of cards, I get the following error.

Anki 24.11 (87ccd24e) (src) (ao)
Python 3.12.8 Qt 6.8.1 PyQt 6.8.0
Platform: Linux-6.12.10-200.fc41.x86_64-x86_64-with-glibc2.40

Traceback (most recent call last):
  File "/app/lib/python3.12/site-packages/aqt/taskman.py", line 144, in _on_closures_pending
    closure()
  File "/app/lib/python3.12/site-packages/aqt/taskman.py", line 88, in <lambda>
    lambda future: self.run_on_main(lambda: on_done(future))
                                            ^^^^^^^^^^^^^^^
  File "/app/lib/python3.12/site-packages/aqt/taskman.py", line 108, in wrapped_done
    on_done(fut)
  File "/app/lib/python3.12/site-packages/aqt/operations/__init__.py", line 117, in wrapped_done
    self._failure(exception)
  File "/home/user/.var/app/net.ankiweb.Anki/data/Anki2/addons21/1772763629/cropro.py", line 470, in on_failure
    raise ex
  File "/usr/lib/python3.12/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.12/site-packages/aqt/operations/__init__.py", line 108, in wrapped_op
    return self._op(mw.col)
           ^^^^^^^^^^^^^^^^
  File "/home/user/.var/app/net.ankiweb.Anki/data/Anki2/addons21/1772763629/cropro.py", line 484, in <lambda>
    op=lambda col: self._importer.import_notes(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.var/app/net.ankiweb.Anki/data/Anki2/addons21/1772763629/note_importer.py", line 217, in import_notes
    return col.merge_undo_entries(pos)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.12/site-packages/anki/collection.py", line 1057, in merge_undo_entries
    return self._backend.merge_undo_entries(target)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.12/site-packages/anki/_backend_generated.py", line 266, in merge_undo_entries
    raw_bytes = self._run_command(3, 11, message.SerializeToString())
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.12/site-packages/anki/_backend.py", line 172, in _run_command
    raise backend_exception_to_pylib(err)
anki.errors.InvalidInput: target undo op not found

===Add-ons (active)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
AJT CroPro  Cross Profile Search and Import ['1772763629', 2024-09-20T03:36, 'None', mod]

===IDs of active AnkiWeb add-ons===
1772763629
@tatsumoto-ren
Copy link
Member

Apparently, Anki just can't handle so many notes at the same time. I remember @dae said that there's a limit on how many undo entries col.merge_undo_entries(pos) can merge, but here there's only one operation between add_custom_undo_entry and merge_undo_entries, so that's confusing to me.

pos = col.add_custom_undo_entry(f"{ADDON_NAME_SHORT}: import {len(notes)} notes")
col.add_notes(requests)
return col.merge_undo_entries(pos)

The add-on uses col.add_notes() instead of col.add_note() exactly to avoid such issues. If you know a workaround, please share.

@dae
Copy link

dae commented Jan 29, 2025

My guess is some other DB op was interleaved between those lines, which could happen if the other caller was not using a collection op to ensure the ops are serialized. TRACESQL=1 might give a hint.

@hundredpinbowling
Copy link
Author

My guess is some other DB op was interleaved between those lines, which could happen if the other caller was not using a collection op to ensure the ops are serialized. TRACESQL=1 might give a hint.

I tried to replicate the error by downloading a huge deck (Ultimate Birds - Images and sounds) and using cropro to import it. For whatever reason, copro had no problems importing 500 cards at a time.
I am not comfortable sharing the TRACESQL log with my main deck as I don't want to dox my cards.

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

No branches or pull requests

3 participants