ankicommunity / ankicommunity-sync-server

A personal Anki sync server (so you can sync against your own server rather than AnkiWeb)
GNU Affero General Public License v3.0
883 stars 81 forks source link

Sync fails after changing cards in any way (apply_graves) #130

Closed croxxx closed 2 years ago

croxxx commented 2 years ago

Summary

While trying to update my Anki instances that hav been running with the old Docker image flawless for years, I came across a problem. Whenever I try to do a regular sync (not a full sync) after any changes I am presented with an error in both AnkiDroid and Anki Desktop ("Please try again later").

Error with AnkiDroid 2.15.6 (latest on F-Droid)

Here's what my server logs show:

[2022-05-07 14:17:18,628]:INFO:ankisyncd.CollectionThread[croxxx]:Running meta(*[], **{'v': 10, 'cv': 'ankidroid,2.15.6,android:8.1.0:GS185'})
[2022-05-07 14:17:18,659]:INFO:ankisyncd.http:172.17.0.1 "POST /sync/meta HTTP/1.0" 200 147
[2022-05-07 14:17:19,136]:INFO:ankisyncd.CollectionThread[croxxx]:Running start(*[], **{'minUsn': 2493, 'lnewer': False, 'graves': {'cards': [], 'notes': [], 'decks': []}})
[2022-05-07 14:17:19,139]:ERROR:ankisyncd.CollectionThread[croxxx]:Unable to start(*[], **{'minUsn': 2493, 'lnewer': False, 'graves': {'cards': [], 'notes': [], 'decks': []}}): 'DeckManager' object has no attribute 'remove'
Traceback (most recent call last):
  File "/opt/ankisyncd/ankisyncd/thread.py", line 98, in _run
    ret = self.wrapper.execute(func, args, kw, return_queue)
  File "/opt/ankisyncd/ankisyncd/collection.py", line 45, in execute
    ret = func(*args, **kw)
  File "/opt/ankisyncd/ankisyncd/sync_app.py", line 712, in run_func
    res = handler_method(**keyword_args)
  File "/opt/ankisyncd/ankisyncd/sync_app.py", line 125, in start
    self.apply_graves(graves,self.maxUsn)
  File "/opt/ankisyncd/ankisyncd/sync.py", line 230, in apply_graves
    self.col.decks.remove(graves['decks'])
AttributeError: 'DeckManager' object has no attribute 'remove'
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/opt/ankisyncd/ankisyncd/sync_app.py", line 517, in __call__
    w= self.__wrapped__(*args, **kwargs)
  File "/opt/ankisyncd/ankisyncd/sync_app.py", line 656, in __call__
    result = self._execute_handler_method_in_thread(url, data, session)
  File "/opt/ankisyncd/ankisyncd/sync_app.py", line 721, in _execute_handler_method_in_thread
    result = thread.execute(run_func, kw=keyword_args)
  File "/opt/ankisyncd/ankisyncd/thread.py", line 79, in execute
    raise ret
  File "/opt/ankisyncd/ankisyncd/thread.py", line 98, in _run
    ret = self.wrapper.execute(func, args, kw, return_queue)
  File "/opt/ankisyncd/ankisyncd/collection.py", line 45, in execute
    ret = func(*args, **kw)
  File "/opt/ankisyncd/ankisyncd/sync_app.py", line 712, in run_func
    res = handler_method(**keyword_args)
  File "/opt/ankisyncd/ankisyncd/sync_app.py", line 125, in start
    self.apply_graves(graves,self.maxUsn)
  File "/opt/ankisyncd/ankisyncd/sync.py", line 230, in apply_graves
    self.col.decks.remove(graves['decks'])
AttributeError: 'DeckManager' object has no attribute 'remove'
[2022-05-07 14:17:19,142]:INFO:ankisyncd.http:172.17.0.1 "POST /sync/start HTTP/1.0" 500 59

Related lines and changes I identified in code:

I noticed the signature was changed from self.col.decks.rem to self.col.decks.remove. Is this possibly just a typo?

croxxx commented 2 years ago

After some more digging, it seems this has already cropped up as part of #110 and was potentially resolved by a dependency upgrade? As #110 was merged in March and I used the latest Docker image ankicommunity/anki-sync-server:20220420, which was built a month after, I assume there is some remaining issue with the dependencies here?

Edit: In case this is simply caused by outdated build dependencies for the Docker image, feel free to close this here and I will file the issue in the respective repository.

VikashKothary commented 2 years ago

As I mentioned in https://github.com/ankicommunity/anki-sync-server/issues/131, I've updated the dependencies and triggered a new build for the docker image. Please let me know if this resolves your issue.

Thank you for bringing this to my attention :)

croxxx commented 2 years ago

Works like a charm now. Thanks for the prompt fix. Closing this and #131.