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

Internal Server Error as accessing knowledge base via API: #14233

Closed
5 tasks done
zhaolj opened this issue Feb 24, 2025 · 2 comments
Closed
5 tasks done

Internal Server Error as accessing knowledge base via API: #14233

zhaolj opened this issue Feb 24, 2025 · 2 comments
Labels
🌚 invalid This doesn't seem right

Comments

@zhaolj
Copy link

zhaolj commented Feb 24, 2025

Self Checks

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

Dify version

1.0.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. deployed with docker images: langgenius/dify-api:main, langgenius/dify-web:main, langgenius/dify-sandbox:0.2.10, langgenius/dify-plugin-daemon:0.0.2-local.
  2. login to Dify, setup the api key for knowledge base.
  3. access to knowledge base api following example document:
curl --location --request GET -k 'http://localhost/v1/datasets?page=1&limit=20' \  
--header 'Authorization: Bearer dataset-RsoU2**********rv0YR'

✔️ Expected Behavior

get the correct response with a list of databases.

❌ Actual Behavior

get the response as:

{"message": "Internal Server Error", "code": "unknown"}

and the logs of dify-api-1 server:

2025-02-24 03:12:57.807 ERROR [Dummy-465] [app.py:875] - Exception on /v1/datasets [GET]
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 157, in decorated
    account = Account.query.filter_by(id=ta.account_id).first()
              ^^^^^^^^^^^^^
AttributeError: type object 'Account' has no attribute 'query'

@dosubot dosubot bot added the 🐞 bug Something isn't working label Feb 24, 2025
Copy link

dosubot bot commented Feb 24, 2025

@zhaolj Hello! I'm here to help you with bug reports, answer questions, and guide you on becoming a contributor. Let's get to the bottom of this issue together.

I found a similar unsolved discussion regarding an internal server error in the Dify repository [1].

The error you're encountering, AttributeError: type object 'Account' has no attribute 'query', suggests that the Account class is missing the query attribute, which is typically provided by SQLAlchemy's BaseQuery when using Flask-SQLAlchemy. This might be due to a misconfiguration or missing setup in your SQLAlchemy model.

Here are a few steps you can take to resolve this issue:

  1. Ensure SQLAlchemy is Properly Configured: Verify that your Account class is correctly set up with SQLAlchemy. The Account class should inherit from a base class that provides the query attribute, typically db.Model if using Flask-SQLAlchemy.

  2. Check Model Imports: Make sure that the Account class is imported from the correct module where it is defined with SQLAlchemy's model base.

  3. Database Initialization: Ensure that the database is properly initialized and that the models are registered with the SQLAlchemy instance.

  4. Review Migrations: Check if there are any pending migrations that need to be applied, as they might affect the database schema related to the Account class [2].

  5. Verify Flask-SQLAlchemy Version: Ensure that the version of Flask-SQLAlchemy you are using is compatible with your setup. The Dify API service uses flask-sqlalchemy version ~3.1.1 [3].

By addressing these areas, you should be able to resolve the AttributeError and get the /v1/datasets endpoint working as expected.

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

@crazywoola
Copy link
Member

We haven't release v1.0.0 yet.

@crazywoola crazywoola added 🌚 invalid This doesn't seem right and removed 🐞 bug Something isn't working labels Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌚 invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants