dify icon indicating copy to clipboard operation
dify copied to clipboard

API Call error 500

Open tientaisv opened this issue 8 months ago • 6 comments

Self Checks

  • [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [x] I have searched for existing issues search for existing issues, including closed ones.
  • [x] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [x] Please do not modify this template :) and fill in all the required fields.

Dify version

1.3.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

2025-04-23 13:49:31.529 ERROR [Dummy-6] [app.py:875] - Exception on /v1/chat-messages [POST]
2025-04-23 13:49:31
 Traceback (most recent call last):
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
2025-04-23 13:49:31
     rv = self.dispatch_request()
2025-04-23 13:49:31
          ^^^^^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
2025-04-23 13:49:31
     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
2025-04-23 13:49:31
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 489, in wrapper
2025-04-23 13:49:31
     resp = resource(*args, **kwargs)
2025-04-23 13:49:31
            ^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/flask/views.py", line 110, in view
2025-04-23 13:49:31
     return current_app.ensure_sync(self.dispatch_request)(**kwargs)  # type: ignore[no-any-return]
2025-04-23 13:49:31
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 604, in dispatch_request
2025-04-23 13:49:31
     resp = meth(*args, **kwargs)
2025-04-23 13:49:31
            ^^^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/controllers/service_api/wraps.py", line 68, in decorated_view
2025-04-23 13:49:31
     .one_or_none()
2025-04-23 13:49:31
      ^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/query.py", line 2754, in one_or_none
2025-04-23 13:49:31
     return self._iter().one_or_none()  # type: ignore
2025-04-23 13:49:31
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py", line 1441, in one_or_none
2025-04-23 13:49:31
     return self._only_one_row(
2025-04-23 13:49:31
            ^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py", line 805, in _only_one_row
2025-04-23 13:49:31
     raise exc.MultipleResultsFound(
2025-04-23 13:49:31
 sqlalchemy.exc.MultipleResultsFound: Multiple rows were found when one or none was required

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

tientaisv avatar Apr 23 '25 13:04 tientaisv

Hello @tientaisv! I'm Dosu, your friendly bot here to help you solve bugs, answer questions, and assist with contributions while you wait for a human maintainer. Let's tackle this issue together!

I found a similar unsolved discussion regarding a "Response[500] Internal Server Error" [1]. This might be related to the issue you're experiencing.

The error you're encountering, MultipleResultsFound, typically occurs when a query that is expected to return one or no results actually returns multiple rows. In the context of the decorated_view method, this exception is raised when the query using one_or_none() finds more than one result. This suggests that the query conditions might not be specific enough, or the data in the database might have duplicates or unexpected entries.

To resolve this issue, you can:

  1. Check the Query Conditions: Ensure that the query conditions in the decorated_view method are correctly set to uniquely identify the expected result. You might need to add more specific filters to the query.

  2. Inspect the Database: Look into the database to verify that the data does not contain duplicates or entries that could lead to multiple results for the query.

  3. Modify the Code: If the query is supposed to handle multiple results, consider using a method that can process multiple rows, such as all() or first(), depending on the logic you need.

If you need further assistance with the specific query or code adjustments, feel free to provide more details or ask additional questions.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Apr 23 '25 13:04 dosubot[bot]

@dosu I'm using a Docker environment, so I can't edit the code directly. At the same time, when I downgrade to a lower version than 0.14, it works fine without this error. Please help me update the Docker image that has fixed this issue, the error with the specific API link in your application.

tientaisv avatar Apr 23 '25 14:04 tientaisv

To update the Docker image and resolve the MultipleResultsFound error by downgrading to a version lower than 0.14, follow these steps:

  1. Open the docker/docker-compose.yaml file in your project.
  2. Change the image version to a version lower than 0.14. For example, update the line from langgenius/dify-web:0.15.3 to langgenius/dify-web:0.13.x.
  3. Run the following commands in your terminal to apply the changes:
    docker compose down
    docker compose pull
    docker compose up -d
    

This will pull the specified version of the Docker image and restart your application with the updated image, which should resolve the error [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Apr 23 '25 14:04 dosubot[bot]

I'm using version 1.3.0.

tientaisv avatar Apr 23 '25 14:04 tientaisv

up

stephonye avatar Apr 24 '25 09:04 stephonye

It seems that there is dirty data in your DB,the tenant-related tables: tenants & tenant_account_joins.

Self Checks

  • [x] This is only for bug report, if you would like to ask a question, please head to Discussions.[x] I have searched for existing issues search for existing issues, including closed ones.[x] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).[x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)[x] Please do not modify this template :) and fill in all the required fields.

Dify version

1.3.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

2025-04-23 13:49:31.529 ERROR [Dummy-6] [app.py:875] - Exception on /v1/chat-messages [POST]
2025-04-23 13:49:31
 Traceback (most recent call last):
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
2025-04-23 13:49:31
     rv = self.dispatch_request()
2025-04-23 13:49:31
          ^^^^^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
2025-04-23 13:49:31
     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
2025-04-23 13:49:31
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 489, in wrapper
2025-04-23 13:49:31
     resp = resource(*args, **kwargs)
2025-04-23 13:49:31
            ^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/flask/views.py", line 110, in view
2025-04-23 13:49:31
     return current_app.ensure_sync(self.dispatch_request)(**kwargs)  # type: ignore[no-any-return]
2025-04-23 13:49:31
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 604, in dispatch_request
2025-04-23 13:49:31
     resp = meth(*args, **kwargs)
2025-04-23 13:49:31
            ^^^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/controllers/service_api/wraps.py", line 68, in decorated_view
2025-04-23 13:49:31
     .one_or_none()
2025-04-23 13:49:31
      ^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/query.py", line 2754, in one_or_none
2025-04-23 13:49:31
     return self._iter().one_or_none()  # type: ignore
2025-04-23 13:49:31
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py", line 1441, in one_or_none
2025-04-23 13:49:31
     return self._only_one_row(
2025-04-23 13:49:31
            ^^^^^^^^^^^^^^^^^^^
2025-04-23 13:49:31
   File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py", line 805, in _only_one_row
2025-04-23 13:49:31
     raise exc.MultipleResultsFound(
2025-04-23 13:49:31
 sqlalchemy.exc.MultipleResultsFound: Multiple rows were found when one or none was required

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

hieheihei avatar Apr 30 '25 04:04 hieheihei

the same error in 1.3.1, when I call the api

^[[A2025-05-16 05:57:38.166 ERROR [Dummy-60] [app.py:875] - Exception on /v1/chat-messages [POST]
Traceback (most recent call last):
  File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 489, in wrapper
    resp = resource(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask/views.py", line 110, in view
    return current_app.ensure_sync(self.dispatch_request)(**kwargs)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 604, in dispatch_request
    resp = meth(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/controllers/service_api/wraps.py", line 68, in decorated_view
    .one_or_none()
     ^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/query.py", line 2754, in one_or_none
    return self._iter().one_or_none()  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py", line 1441, in one_or_none
    return self._only_one_row(
           ^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py", line 805, in _only_one_row
    raise exc.MultipleResultsFound(
sqlalchemy.exc.MultipleResultsFound: Multiple rows were found when one or none was required


geosmart avatar May 16 '25 05:05 geosmart

File "/app/api/controllers/service_api/wraps.py", line 68, in decorated_view


            tenant_account_join = (
                db.session.query(Tenant, TenantAccountJoin)
                .filter(Tenant.id == api_token.tenant_id)
                .filter(TenantAccountJoin.tenant_id == Tenant.id)
                .filter(TenantAccountJoin.role.in_(["owner"]))
                .filter(Tenant.status == TenantStatus.NORMAL)
                .one_or_none()
            )  # TODO: only owner information is required, so only one is returned.

limit only one owner make this error!

I have multiple owner user, so just replace .one_or_none() to .first() save me

sed -i 's/\.one_or_none()/\.first()/g' /app/api/controllers/service_api/wraps.py

geosmart avatar May 16 '25 06:05 geosmart

Let just change .one_or_none() to first() ?

lambdaq avatar Jun 20 '25 09:06 lambdaq

Hi @geosmart,

According to our design, each tenant is assigned only one owner. Could you please explain how multiple owners were assigned?

laipz8200 avatar Jun 20 '25 10:06 laipz8200