jointakahe / takahe

An ActivityPub/Fediverse server
BSD 3-Clause "New" or "Revised" License
1.12k stars 85 forks source link

KeyError: 'mediaType' #291

Closed kromonos closed 1 year ago

kromonos commented 1 year ago

Looks like addressing an array key, which doesn't exist.

inbox-runner-1         | Attempting transition on users.inboxmessage#67676 from state received
inbox-runner-1         | Traceback (most recent call last):
inbox-runner-1         |   File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 486, in thread_handler
inbox-runner-1         |     raise exc_info[1]
inbox-runner-1         |   File "/takahe/stator/models.py", line 172, in atransition_attempt
inbox-runner-1         |     next_state = await current_state.handler(self)  # type: ignore
inbox-runner-1         |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
inbox-runner-1         |   File "/takahe/users/models/inbox_message.py", line 31, in handle_received
inbox-runner-1         |     await sync_to_async(Post.handle_create_ap)(instance.message)
inbox-runner-1         |   File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 448, in __call__
inbox-runner-1         |     ret = await asyncio.wait_for(future, timeout=None)
inbox-runner-1         |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
inbox-runner-1         |   File "/usr/local/lib/python3.11/asyncio/tasks.py", line 442, in wait_for
inbox-runner-1         |     return await fut
inbox-runner-1         |            ^^^^^^^^^
inbox-runner-1         |   File "/usr/local/lib/python3.11/site-packages/asgiref/current_thread_executor.py", line 22, in run
inbox-runner-1         |     result = self.fn(*self.args, **self.kwargs)
inbox-runner-1         |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
inbox-runner-1         |   File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 490, in thread_handler
inbox-runner-1         |     return func(*args, **kwargs)
inbox-runner-1         |            ^^^^^^^^^^^^^^^^^^^^^
inbox-runner-1         |   File "/takahe/activities/models/post.py", line 806, in handle_create_ap
inbox-runner-1         |     cls.by_ap(data["object"], create=True, update=True)
inbox-runner-1         |   File "/takahe/activities/models/post.py", line 723, in by_ap
inbox-runner-1         |     emoji = Emoji.by_ap_tag(post.author.domain, tag, create=True)
inbox-runner-1         |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
inbox-runner-1         |   File "/takahe/activities/models/emoji.py", line 237, in by_ap_tag
inbox-runner-1         |     mimetype=icon["mediaType"],
inbox-runner-1         |              ~~~~^^^^^^^^^^^^^
inbox-runner-1         | KeyError: 'mediaType'
andrewgodwin commented 1 year ago

Any chance you could go get the content of inbox message #67676 and post it here?

kromonos commented 1 year ago
{
  "cc": "as:Public",
  "id": "https://social.alster.space/activities/47d8a0f1-850e-435c-8569-f1f622f65138",
  "to": [
    "https://social.alster.space/users/alsternerd",
    "https://social.alster.space/users/alsternerd/followers"
  ],
  "type": "Create",
  "actor": "https://social.alster.space/users/alsternerd",
  "object": {
    "cc": "as:Public",
    "id": "https://social.alster.space/objects/d9a10560-09b2-409d-9cee-b984111d62c0",
    "to": [
      "https://social.alster.space/users/alsternerd",
      "https://social.alster.space/users/alsternerd/followers"
    ],
    "tag": [
      {
        "href": "https://social.alster.space/users/alsternerd",
        "type": "Mention",
        "nameMap": {
          "und": "@alsternerd"
        }
      },
      {
        "id": "https://social.alster.space/emoji/blobcat/blobcatfacepalm.png",
        "icon": {
          "url": "https://social.alster.space/emoji/blobcat/blobcatfacepalm.png",
          "type": "Image"
        },
        "type": "Emoji",
        "nameMap": {
          "und": ":blobcatfacepalm:"
        },
        "updated": "1970-01-01T00:00:00Z"
      }
    ],
    "type": "Note",
    "actor": "https://social.alster.space/users/alsternerd",
    "source": {
      "mediaType": {
        "@value": "text/plain",
        "@language": "und"
      },
      "contentMap": {
        "und": "Aber sie haben 7-fach Schaltwerke in Rapidfire und Drehschalter. :blobcatfacepalm:"
      }
    },
    "context": "https://social.alster.space/contexts/51e41d2c-51b8-4046-bce9-f1eb0e20d2a8",
    "inReplyTo": "https://social.alster.space/objects/ef106453-2b75-487a-8455-9cc818755fee",
    "published": "2022-12-27T14:08:08.224660Z",
    "attachment": [],
    "contentMap": {
      "und": "Aber sie haben 7-fach Schaltwerke in Rapidfire und Drehschalter. :blobcatfacepalm:"
    },
    "summaryMap": {
      "und": ""
    },
    "attributedTo": "https://social.alster.space/users/alsternerd",
    "http://ostatus.org#conversation": {
      "id": "https://social.alster.space/contexts/51e41d2c-51b8-4046-bce9-f1eb0e20d2a8"
    }
  },
  "context": "https://social.alster.space/contexts/51e41d2c-51b8-4046-bce9-f1eb0e20d2a8",
  "@context": [
    "https://www.w3.org/ns/activitystreams",
    {
      "toot": "http://joinmastodon.org/ns#",
      "Emoji": "toot:Emoji",
      "Public": "as:Public",
      "Hashtag": "as:Hashtag",
      "blurhash": "toot:blurhash",
      "sensitive": "as:sensitive",
      "focalPoint": {
        "@id": "toot:focalPoint",
        "@container": "@list"
      },
      "votersCount": "toot:votersCount",
      "manuallyApprovesFollowers": "as:manuallyApprovesFollowers"
    },
    "https://w3id.org/security/v1"
  ],
  "published": "2022-12-27T14:08:08.224582Z",
  "http://litepub.social/ns#directMessage": false
}
andrewgodwin commented 1 year ago

Fascinating, we'll have to see if this is valid or if Pleroma is breaking the spec.

manfre commented 1 year ago

I ran in to one of these silly und mimetypes too. Have a PR that ignores the question about whether und is valid here and avoids the key error.