Mintplex-Labs / anything-llm

The all-in-one Desktop & Docker AI application with built-in RAG, AI agents, and more.
https://anythingllm.com
MIT License
25.41k stars 2.57k forks source link

[BUG]: Incorrect 200 Response from /v1/workspace/{slug}/update Endpoint with Invalid Payload #2541

Open MrSimonC opened 4 days ago

MrSimonC commented 4 days ago

How are you running AnythingLLM?

Docker (remote machine)

What happened?

When calling the endpoint /v1/workspace/{slug}/update with a POST request and the following payload:

{
  "name": "Updated Workspace Name",
  "openAiHistory": null
}

the endpoint incorrectly returns a 200 status code with the following message:

{
  "workspace": null,
  "message": "\nInvalid `prisma.workspaces.update()` invocation:\n\n{\n  where: {\n    id: 17\n  },\n  data: {\n    name: \"basssis Updated Workspace Name\",\n+   openAiHistory: Int\n  }\n}\n\nArgument `openAiHistory` must not be null."
}

The response indicates an error in the prisma.workspaces.update() invocation due to the openAiHistory field being null, which is not allowed.

Additional Information: This issue leads to confusion as the status code 200 OK suggests that the operation was successful, while the message indicates an error. Proper error handling is required to ensure the API behaves as expected.

Suggested Fix:

Are there known steps to reproduce?

Expected Behavior:

Steps to Reproduce:

  1. Deploy the API using Docker.
  2. Send a POST request to /v1/workspace/{slug}/update with the following payload:
    {
     "name": "Updated Workspace Name",
     "openAiHistory": null
    }
  3. Observe the response status code and message.

Actual Response:

timothycarambat commented 3 days ago

In the interim, openAiHistory should be any non-zero number - 20 is the default. This is the amount of chat history included in a chat response.

Wrt this issue, each writable field should have some conditional form of validation - which was omitted historically to prevent non-writable fields from being edited via the Workspace.update method.