Conversations endpoint returning 500s for valid requests #1594

Closed
opened 2020-03-01 14:11:35 +00:00 by tk · 7 comments
Member

Commit: c27d1d65bf

I've been playing around with the /api/v1/pleroma/conversations/:id/statuses endpoint as part of investigating possible new functionality for a script I'm writing, but I can't get it to return successfully. Both wget and a proper OAuth-based script get this:

Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: 06:03:51.462 request_id=FfgzFFYJsDqP0CkANZFh [error] Internal server error: %UndefinedFunctionError{arity: 0, function: :user_id, message: nil, module: nil, reason: nil}
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: 06:03:51.462 request_id=FfgzFFYJsDqP0CkANZFh [info] Converted error :undef to 500 response
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: 06:03:51.465 [error] #PID<0.8672.97> running Pleroma.Web.Endpoint (connection #PID<0.8665.97>, stream id 1) terminated
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: Server: bbs.kawa-kun.com:80 (http)
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: Request: GET /api/v1/pleroma/conversations/237569/statuses
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: ** (exit) an exception was raised:
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]:     ** (UndefinedFunctionError) function nil.user_id/0 is undefined
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]:         nil.user_id()
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]:         (pleroma 1.1.50-2510-g61e48fd8-bbs-kawa-kun-com) lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex:108: Pleroma.Web.PleromaAPI.PleromaAPIController.conversation_statuses/2
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]:         (pleroma 1.1.50-2510-g61e48fd8-bbs-kawa-kun-com) lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex:5: Pleroma.Web.PleromaAPI.PleromaAPIController.action/2
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]:         (pleroma 1.1.50-2510-g61e48fd8-bbs-kawa-kun-com) lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex:5: Pleroma.Web.PleromaAPI.PleromaAPIController.phoenix_controller_pipeline/2
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]:         (pleroma 1.1.50-2510-g61e48fd8-bbs-kawa-kun-com) lib/pleroma/web/endpoint.ex:5: Pleroma.Web.Endpoint.instrument/4
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]:         (phoenix 1.4.10) lib/phoenix/router.ex:288: Phoenix.Router.__call__/2
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]:         (pleroma 1.1.50-2510-g61e48fd8-bbs-kawa-kun-com) lib/pleroma/web/endpoint.ex:5: Pleroma.Web.Endpoint.plug_builder_call/2
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]:         (pleroma 1.1.50-2510-g61e48fd8-bbs-kawa-kun-com) lib/pleroma/web/endpoint.ex:5: Pleroma.Web.Endpoint.call/2
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: 06:03:51.463 [error] CRASH REPORT Process <0.8672.97> with 0 neighbours exited with reason: {{#{'__exception__' => true,'__struct__' => 'Elixir.UndefinedFunctionError',arity => 0,function => user_id,message => nil,module => nil,reason => nil},[{nil,user_id,[],[]},{'Elixir.Pleroma.Web.PleromaAPI.PleromaAPIController',conversation_statuses,2,[{file,"lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex"},{line,108}]},{'Elixir.Pleroma.Web.PleromaAPI.PleromaAPIController',action,2,[{file,"lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex"},{line,5}]},{'Elixir.Pleroma.Web.PleromaAPI.PleromaAPIController',...},...]},...} in 'Elixir.Phoenix.Endpoint.Cowboy2Handler':init/4 line 59 in 'Elixir.Phoenix.Endpoint.Cowboy2Handler':init/4 line 59
Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: 06:03:51.465 [error] Cowboy stream 1 with ranch listener 'Elixir.Pleroma.Web.Endpoint.HTTP' and connection process <0.8665.97> had its request process exit with reason: {{#{'__exception__' => true,'__struct__' => 'Elixir.UndefinedFunctionError',arity => 0,function => user_id,message => nil,module => nil,reason => nil},[{nil,user_id,[],[]},{'Elixir.Pleroma.Web.PleromaAPI.PleromaAPIController',conversation_statuses,2,[{file,"lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex"},{line,108}]},{'Elixir.Pleroma.Web.PleromaAPI.PleromaAPIController',action,2,[{file,"lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex"},{line,5}]},{'Elixir.Pleroma.Web.PleromaAPI.PleromaAPIController',...},...]},...} in 'Elixir.Phoenix.Endpoint.Cowboy2Handler':init/4 line 59

The conversation ID is from here, so it should be valid.

EDIT: Fix formatting

Commit: c27d1d65bfd60effdb45359697141c136e156177 I've been playing around with the [`/api/v1/pleroma/conversations/:id/statuses`](https://docs-develop.pleroma.social/backend/API/pleroma_api/#get-apiv1pleromaconversationsidstatuses) endpoint as part of investigating possible new functionality for a script I'm writing, but I can't get it to return successfully. Both `wget` and a proper OAuth-based script get this: ``` Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: 06:03:51.462 request_id=FfgzFFYJsDqP0CkANZFh [error] Internal server error: %UndefinedFunctionError{arity: 0, function: :user_id, message: nil, module: nil, reason: nil} Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: 06:03:51.462 request_id=FfgzFFYJsDqP0CkANZFh [info] Converted error :undef to 500 response Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: 06:03:51.465 [error] #PID<0.8672.97> running Pleroma.Web.Endpoint (connection #PID<0.8665.97>, stream id 1) terminated Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: Server: bbs.kawa-kun.com:80 (http) Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: Request: GET /api/v1/pleroma/conversations/237569/statuses Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: ** (exit) an exception was raised: Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: ** (UndefinedFunctionError) function nil.user_id/0 is undefined Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: nil.user_id() Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: (pleroma 1.1.50-2510-g61e48fd8-bbs-kawa-kun-com) lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex:108: Pleroma.Web.PleromaAPI.PleromaAPIController.conversation_statuses/2 Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: (pleroma 1.1.50-2510-g61e48fd8-bbs-kawa-kun-com) lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex:5: Pleroma.Web.PleromaAPI.PleromaAPIController.action/2 Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: (pleroma 1.1.50-2510-g61e48fd8-bbs-kawa-kun-com) lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex:5: Pleroma.Web.PleromaAPI.PleromaAPIController.phoenix_controller_pipeline/2 Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: (pleroma 1.1.50-2510-g61e48fd8-bbs-kawa-kun-com) lib/pleroma/web/endpoint.ex:5: Pleroma.Web.Endpoint.instrument/4 Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: (phoenix 1.4.10) lib/phoenix/router.ex:288: Phoenix.Router.__call__/2 Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: (pleroma 1.1.50-2510-g61e48fd8-bbs-kawa-kun-com) lib/pleroma/web/endpoint.ex:5: Pleroma.Web.Endpoint.plug_builder_call/2 Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: (pleroma 1.1.50-2510-g61e48fd8-bbs-kawa-kun-com) lib/pleroma/web/endpoint.ex:5: Pleroma.Web.Endpoint.call/2 Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: 06:03:51.463 [error] CRASH REPORT Process <0.8672.97> with 0 neighbours exited with reason: {{#{'__exception__' => true,'__struct__' => 'Elixir.UndefinedFunctionError',arity => 0,function => user_id,message => nil,module => nil,reason => nil},[{nil,user_id,[],[]},{'Elixir.Pleroma.Web.PleromaAPI.PleromaAPIController',conversation_statuses,2,[{file,"lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex"},{line,108}]},{'Elixir.Pleroma.Web.PleromaAPI.PleromaAPIController',action,2,[{file,"lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex"},{line,5}]},{'Elixir.Pleroma.Web.PleromaAPI.PleromaAPIController',...},...]},...} in 'Elixir.Phoenix.Endpoint.Cowboy2Handler':init/4 line 59 in 'Elixir.Phoenix.Endpoint.Cowboy2Handler':init/4 line 59 Mar 01 06:03:51 bbs.kawa-kun.com mix[2634]: 06:03:51.465 [error] Cowboy stream 1 with ranch listener 'Elixir.Pleroma.Web.Endpoint.HTTP' and connection process <0.8665.97> had its request process exit with reason: {{#{'__exception__' => true,'__struct__' => 'Elixir.UndefinedFunctionError',arity => 0,function => user_id,message => nil,module => nil,reason => nil},[{nil,user_id,[],[]},{'Elixir.Pleroma.Web.PleromaAPI.PleromaAPIController',conversation_statuses,2,[{file,"lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex"},{line,108}]},{'Elixir.Pleroma.Web.PleromaAPI.PleromaAPIController',action,2,[{file,"lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex"},{line,5}]},{'Elixir.Pleroma.Web.PleromaAPI.PleromaAPIController',...},...]},...} in 'Elixir.Phoenix.Endpoint.Cowboy2Handler':init/4 line 59 ``` The conversation ID is from [here](https://bbs.kawa-kun.com/api/v1/statuses/9sHFuAlkBgUDZZNAlU), so it should be valid. EDIT: Fix formatting
Author
Member

Still occurs in 438394d404 .

Still occurs in 438394d40447bdfb590ff206ad80907294da0e65 .
Owner

wget is probably not the best one there as it's pretty limited specially for authentication, would recommend curl instead, specially as ~every (Gecko, Blink, WebKit) browser devtools will give you a curl command to reproduce their requests.

And it looks like you managed to get the conversation_id off a bit?

$ curl -sSL https://bbs.kawa-kun.com/api/v1/statuses/9sHFuAlkBgUDZZNAlU | jq .pleroma
{
  "content": {
    "text/plain": "@seven I was referring to the Android App (fork of Tusky), but awww cute doggo :3"
  },
  "conversation_id": 258665,
  "direct_conversation_id": null,
  "emoji_reactions": [],
  "expires_at": null,
  "in_reply_to_account_acct": "seven@social.panthermodern.net",
  "local": false,
  "spoiler_text": {
    "text/plain": ""
  },
  "thread_muted": false
}
`wget` is probably not the best one there as it's pretty limited specially for authentication, would recommend `curl` instead, specially as ~every (Gecko, Blink, WebKit) browser devtools will give you a `curl` command to reproduce their requests. And it looks like you managed to get the `conversation_id` off a bit? ```json $ curl -sSL https://bbs.kawa-kun.com/api/v1/statuses/9sHFuAlkBgUDZZNAlU | jq .pleroma { "content": { "text/plain": "@seven I was referring to the Android App (fork of Tusky), but awww cute doggo :3" }, "conversation_id": 258665, "direct_conversation_id": null, "emoji_reactions": [], "expires_at": null, "in_reply_to_account_acct": "seven@social.panthermodern.net", "local": false, "spoiler_text": { "text/plain": "" }, "thread_muted": false } ```
Author
Member

This is the main I've been using for testing, with CLIENT being the dictionary returned by the app registration endpoint: test_request.py

This is the actual source of the conversation ID: https://bbs.kawa-kun.com/api/v1/statuses/9sDEZj62UFx3MxiEnQ (sorry about my mistake when pasting it). Here's the pleroma section:

{
    "pleroma": {
        "content": {
            "text/plain": "For those in the US, who are you voting for president in 2020?"
        },
        "conversation_id": 237569,
        "direct_conversation_id": null,
        "emoji_reactions": [],
        "expires_at": null,
        "in_reply_to_account_acct": null,
        "local": true,
        "spoiler_text": {
            "text/plain": ""
        },
        "thread_muted": false
    },
}

Here's the output of the script:

Got token: {'access_token': '<REDACTED>',
 'expires_at': 1583116571.73447,
 'expires_in': 600,
 'me': 'https://bbs.kawa-kun.com/users/tk',
 'refresh_token': '<REDACTED>',
 'scope': ['read'],
 'token_type': 'Bearer'}
{'errors': {'detail': 'Internal server error'}}
Traceback (most recent call last):
  File "test_request.py", line 35, in <module>
    r.raise_for_status()
  File "/usr/lib/python3.8/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://bbs.kawa-kun.com/api/v1/pleroma/conversations/237569/statuses

I tried the script on another conversation (353946) and got the same error aside from the tokens and conversation ID in the log, too.

This is the main I've been using for testing, with `CLIENT` being the dictionary returned by the app registration endpoint: [test_request.py](/uploads/92c0e93f9787493538abcd69b21215c6/test_request.py) This is the actual source of the conversation ID: `https://bbs.kawa-kun.com/api/v1/statuses/9sDEZj62UFx3MxiEnQ` (sorry about my mistake when pasting it). Here's the `pleroma` section: ```json { "pleroma": { "content": { "text/plain": "For those in the US, who are you voting for president in 2020?" }, "conversation_id": 237569, "direct_conversation_id": null, "emoji_reactions": [], "expires_at": null, "in_reply_to_account_acct": null, "local": true, "spoiler_text": { "text/plain": "" }, "thread_muted": false }, } ``` Here's the output of the script: ``` Got token: {'access_token': '<REDACTED>', 'expires_at': 1583116571.73447, 'expires_in': 600, 'me': 'https://bbs.kawa-kun.com/users/tk', 'refresh_token': '<REDACTED>', 'scope': ['read'], 'token_type': 'Bearer'} {'errors': {'detail': 'Internal server error'}} Traceback (most recent call last): File "test_request.py", line 35, in <module> r.raise_for_status() File "/usr/lib/python3.8/site-packages/requests/models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://bbs.kawa-kun.com/api/v1/pleroma/conversations/237569/statuses ``` I tried the script on another conversation (353946) and got the same error aside from the tokens and conversation ID in the log, too.
Owner

Ah, I found why. The name of the keys in this API are crap… It is with direct_conversation_id not conversation_id.

Ah, I found why. The name of the keys in this API are crap… It is with `direct_conversation_id` *not* `conversation_id`.
Author
Member

That leaves me with two questions:

  1. Since these notes all have direct_conversation_id set to null, how I can I fetch the full conversation via the API given the start of the thread? I don't think I've ever seen direct_conversation_id set in my playing around with various APIs.
  2. What purpose does conversation_id serve?
That leaves me with two questions: 1. Since these notes all have `direct_conversation_id` set to null, how I can I fetch the full conversation via the API given the start of the thread? I don't think I've ever seen `direct_conversation_id` set in my playing around with various APIs. 2. What purpose does `conversation_id` serve?
Owner
  1. direct_conversation_id is present in direct messages, the conversation API is for them.
  2. It is for the context/thread, it should be renamed to context_id but it's going to be a pain to do so as it would mean breaking the API at some point
1. `direct_conversation_id` is present in direct messages, the conversation API is for them. 2. It is for the context/thread, it should be renamed to `context_id` but it's going to be a pain to do so as it would mean breaking the API at some point
Author
Member

So…how can I fetch a full thread of public messages starting from the first one via the Mastodon/Pleroma API? Here is a GS thread example.

Scratch that. It looks like /api/v1/statuses/:id/context is what I want.

~~So…how can I fetch a full thread of public messages starting from the first one via the Mastodon/Pleroma API? [Here](https://loadaverage.org/conversation/13609164) is a GS thread example.~~ Scratch that. It looks like `/api/v1/statuses/:id/context` is what I want.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pleroma/pleroma#1594
No description provided.