Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MrSimonC opened this issue Oct 27, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@MrSimonC
Copy link
Contributor

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:

  • Validate the payload before attempting to update the workspace. If openAiHistory is null and not allowed, return a 400 Bad Request status code with a clear error message.
  • Alternatively, modify the update logic to ignore null values for fields where null is not allowed, and proceed with updating the other valid fields.

Are there known steps to reproduce?

Expected Behavior:

  • The endpoint should return an appropriate error code (e.g., 400 Bad Request) if the openAiHistory field is null and cannot be processed.
  • Alternatively, the API should ignore the null value for openAiHistory and update the workspace with the provided valid fields, returning a 200 status code only if the operation is successful.

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:

  • Status Code: 200 OK
  • Response Body:
    {
      "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."
    }
@MrSimonC MrSimonC added the possible bug Bug was reported but is not confirmed or is unable to be replicated. label Oct 27, 2024
@timothycarambat
Copy link
Member

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.

@timothycarambat timothycarambat added enhancement New feature or request and removed possible bug Bug was reported but is not confirmed or is unable to be replicated. labels Oct 28, 2024
@timothycarambat timothycarambat self-assigned this Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants