bookwyrm-social / bookwyrm

Social reading and reviewing, decentralized with ActivityPub
http://joinbookwyrm.com/
Other
2.17k stars 255 forks source link

Account import fails with error: 'attributedTo' #3381

Open dnoesgaard opened 3 weeks ago

dnoesgaard commented 3 weeks ago

I'm trying to import an account, but the import fails. Only 60 out of ~500 books are imported and see this in the logs:

celery_worker-1   | [2024-06-09 11:57:38,222: ERROR/ForkPoolWorker-4] User Import Job 4 Failed with error: 'attributedTo'
celery_worker-1   | Traceback (most recent call last):
celery_worker-1   |   File "/app/bookwyrm/models/bookwyrm_import_job.py", line 63, in start_import_task
celery_worker-1   |     process_books(job, tar)
celery_worker-1   |   File "/app/bookwyrm/models/bookwyrm_import_job.py", line 92, in process_books
celery_worker-1   |     upsert_statuses(
celery_worker-1   |   File "/app/bookwyrm/models/bookwyrm_import_job.py", line 185, in upsert_statuses
celery_worker-1   |     user, status["attributedTo"]
celery_worker-1   |           ~~~~~~^^^^^^^^^^^^^^^^
celery_worker-1   | KeyError: 'attributedTo'

I'm attaching archive.json from the export tarball archive.json

Any idea what might be the reason?

hughrun commented 1 week ago

oof, that's a bug.

In your export there's a Tombstone comment for the book "Piranesi":

{
    "id": "https://books.theunseen.city/user/daniel/comment/50874",
    "type": "Tombstone",
    "@context": "https://www.w3.org/ns/activitystreams",
    "progress": null,
    "progress_mode": "PG"
}

Because it's a Tombstone, it can't be attributed to any user, so it doesn't have an attributedTo key or value, hence the loop fails with a KeyError.

There really needs to be some more robust exception checking in the user account import process generally but in this case we just need to skip this section and import the comment as-is.