这是indexloc提供的服务,不要输入任何密码
Skip to content

[BUG]: Error Creating New Thread with userId in Workspace API #2272

@MrSimonC

Description

@MrSimonC

How are you running AnythingLLM?

Docker (local)

What happened?

(Sorry - no pull request from me this time - it's too in depth 😄 )
When attempting to create a new thread in a workspace using the API and providing a userId, an error occurs. This issue can be reproduced using the provided code or directly in the Swagger UI.

Environment:

  • Running AnythingLLM in Docker
  • Version: 1.2.2 (also tested in 1.2.1)
  • Tested on Windows WSL2 Docker and Ubuntu in GitHub Codespaces

Are there known steps to reproduce?

  1. Run AnythingLLM in Docker:

    export STORAGE_LOCATION=$HOME/anythingllm && \
    mkdir -p $STORAGE_LOCATION && \
    touch "$STORAGE_LOCATION/.env" && \
    docker run -d -p 3001:3001 \
    --cap-add SYS_ADMIN \
    -v ${STORAGE_LOCATION}:/app/server/storage \
    -v ${STORAGE_LOCATION}/.env:/app/server/.env \
    -e STORAGE_DIR="/app/server/storage" \
    --restart always \
    mintplexlabs/anythingllm:1.2.2
  2. Fill in a new AI provider.

  3. Generate a new API key (e.g., <MY_API_KEY>).

HTTP REST Example:

POST http://localhost:3001/api/v1/workspace/my-workspace-slug/thread/new
Authorization: Bearer <MY_API_KEY>
Content-Type: application/json

{
  "userId": 1
}

CURL Example:

curl -X 'POST' \
  'http://127.0.0.1:3001/api/v1/workspace/my-workspace-slug/thread/new' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <MY_API_KEY>' \
  -H 'Content-Type: application/json' \
  -d '{
  "userId": 1
}'

Result:
The API responds with:

HTTP/1.1 200 OK
X-Powered-By: Express
Vary: Origin
Content-Type: application/json; charset=utf-8
Content-Length: 148
ETag: W/"94-Y14XDftRy07iOWO+P2NlTX+rhlw"
Date: Thu, 12 Sep 2024 16:06:54 GMT
Connection: keep-alive
keep-alive: timeout=5

{
  "thread": null,
  "message": "\nInvalid `prisma.workspace_threads.create()` invocation:\n\n\nForeign key constraint failed on the field: `foreign key`"
}

Expected Behavior:
The thread should be created successfully when a valid userId is provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    possible bugBug was reported but is not confirmed or is unable to be replicated.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions