Dify knowledge base API ,response "Internal Server Error" #20420

Closed
opened 2026-02-21 20:07:23 -05:00 by yindo · 1 comment
Owner

Originally created by @zhaoyinlong123 on GitHub (Nov 19, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • 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, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.9.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Call the Dify knowledge base API: /v1/datasets, Request parameters:
{
"page": 1,
"limit": 10
}

✔️ Expected Behavior

{
"data": [
{
"id": "b433b138-6b10-4241-b81e-c2dce1e1d79d",
"name": "\u96c6\u56e2\u5b89\u5168\u5236\u5ea6",
"description": "useful for when you want to answer queries about the QBCU YG243007-2024 \u4e2d\u56fd\u8054\u901a\u7535\u4fe1\u5361\u6570\u636e\u5b89\u5168\u7ba1\u7406\u529e\u6cd5V1.0.pdf",
"provider": "vendor",
"permission": "only_me",
"data_source_type": "upload_file",
"indexing_technique": "high_quality",
"app_count": 1,
"document_count": 39,
"word_count": 268757,
"created_by": "9eb173b9-f320-47c1-893d-836d082bf16d",
"created_at": 1762307769,
"updated_by": "9eb173b9-f320-47c1-893d-836d082bf16d",
"updated_at": 1762310028,
"embedding_model": "bge-m3:latest",
"embedding_model_provider": "langgenius/ollama/ollama",
"embedding_available": true,
"retrieval_model_dict": {
"search_method": "semantic_search",
"reranking_enable": false,
"reranking_mode": "weighted_score",
"reranking_model": {
"reranking_provider_name": "",
"reranking_model_name": ""
},
"weights": {
"weight_type": "customized",
"keyword_setting": {
"keyword_weight": 0.3
},
"vector_setting": {
"vector_weight": 0.7,
"embedding_model_name": "dengcao/Qwen3-Embedding-0.6B:F16",
"embedding_provider_name": "langgenius/ollama/ollama"
}
},
"top_k": 5,
"score_threshold_enabled": false,
"score_threshold": 0.0
},
"tags": [],
"doc_form": "text_model",
"external_knowledge_info": {
"external_knowledge_id": null,
"external_knowledge_api_id": null,
"external_knowledge_api_name": null,
"external_knowledge_api_endpoint": null
},
"external_retrieval_model": {
"top_k": 5,
"score_threshold": 0.0,
"score_threshold_enabled": false
},
"doc_metadata": [],
"built_in_field_enabled": false,
"pipeline_id": null,
"runtime_mode": "general",
"chunk_structure": null,
"icon_info": {
"icon_type": "emoji",
"icon": "",
"icon_background": "",
"icon_url": null
},
"is_published": false,
"total_documents": 39,
"total_available_documents": 1,
"enable_api": true,
"partial_member_list": []
},
{
"id": "6da76311-9251-459c-b36e-a78b00461ec8",
"name": "Network security knowledge",
"description": "",
"provider": "vendor",
"permission": "all_team_members",
"data_source_type": "upload_file",
"indexing_technique": "high_quality",
"app_count": 2,
"document_count": 1,
"word_count": 3083,
"created_by": "a1f1611b-d7b6-48a3-ba56-4582d12bb1b1",
"created_at": 1761899329,
"updated_by": "a1f1611b-d7b6-48a3-ba56-4582d12bb1b1",
"updated_at": 1762331189,
"embedding_model": "dengcao/Qwen3-Embedding-0.6B:F16",
"embedding_model_provider": "langgenius/ollama/ollama",
"embedding_available": true,
"retrieval_model_dict": {
"search_method": "hybrid_search",
"reranking_enable": false,
"reranking_mode": "weighted_score",
"reranking_model": {
"reranking_provider_name": "",
"reranking_model_name": ""
},
"weights": {
"weight_type": "customized",
"keyword_setting": {
"keyword_weight": 0.3
},
"vector_setting": {
"vector_weight": 0.7,
"embedding_model_name": "dengcao/Qwen3-Embedding-0.6B:F16",
"embedding_provider_name": "langgenius/ollama/ollama"
}
},
"top_k": 3,
"score_threshold_enabled": true,
"score_threshold": 0.5
},
"tags": [],
"doc_form": "hierarchical_model",
"external_knowledge_info": {
"external_knowledge_id": null,
"external_knowledge_api_id": null,
"external_knowledge_api_name": null,
"external_knowledge_api_endpoint": null
},
"external_retrieval_model": {
"top_k": 3,
"score_threshold": 0.5,
"score_threshold_enabled": true
},
"doc_metadata": [],
"built_in_field_enabled": false,
"pipeline_id": null,
"runtime_mode": "general",
"chunk_structure": null,
"icon_info": {
"icon_type": "emoji",
"icon": "",
"icon_background": "",
"icon_url": null
},
"is_published": false,
"total_documents": 1,
"total_available_documents": 1,
"enable_api": true,
"partial_member_list": []
},
{
"id": "8f214295-3d0f-43e9-aee2-d2cab2d2366e",
"name": "Security rules and regulations",
"description": "",
"provider": "vendor",
"permission": "all_team_members",
"data_source_type": "upload_file",
"indexing_technique": "high_quality",
"app_count": 2,
"document_count": 5,
"word_count": 47627,
"created_by": "a1f1611b-d7b6-48a3-ba56-4582d12bb1b1",
"created_at": 1761878571,
"updated_by": "a1f1611b-d7b6-48a3-ba56-4582d12bb1b1",
"updated_at": 1762331179,
"embedding_model": "dengcao/Qwen3-Embedding-0.6B:F16",
"embedding_model_provider": "langgenius/ollama/ollama",
"embedding_available": true,
"retrieval_model_dict": {
"search_method": "hybrid_search",
"reranking_enable": false,
"reranking_mode": "weighted_score",
"reranking_model": {
"reranking_provider_name": "",
"reranking_model_name": ""
},
"weights": {
"weight_type": "customized",
"keyword_setting": {
"keyword_weight": 0.3
},
"vector_setting": {
"vector_weight": 0.7,
"embedding_model_name": "dengcao/Qwen3-Embedding-0.6B:F16",
"embedding_provider_name": "langgenius/ollama/ollama"
}
},
"top_k": 3,
"score_threshold_enabled": true,
"score_threshold": 0.5
},
"tags": [],
"doc_form": "hierarchical_model",
"external_knowledge_info": {
"external_knowledge_id": null,
"external_knowledge_api_id": null,
"external_knowledge_api_name": null,
"external_knowledge_api_endpoint": null
},
"external_retrieval_model": {
"top_k": 3,
"score_threshold": 0.5,
"score_threshold_enabled": true
},
"doc_metadata": [],
"built_in_field_enabled": false,
"pipeline_id": null,
"runtime_mode": "general",
"chunk_structure": null,
"icon_info": {
"icon_type": "emoji",
"icon": "",
"icon_background": "",
"icon_url": null
},
"is_published": false,
"total_documents": 5,
"total_available_documents": 5,
"enable_api": true,
"partial_member_list": []
},
{
"id": "b69a96a6-2bdb-48e5-8fd7-aa9b829a8df5",
"name": "\u50a8\u80fd\u7814\u62a5",
"description": "useful for when you want to answer queries about the 20250811-\u534e\u5b89\u8bc1\u5238-\u534e\u5b89\u8bc1\u5238\u7535\u529b\u8bbe\u5907\u884c\u4e1a\u5468\u62a5\uff1a\u6d77\u98ce\u9879\u76ee\u5bc6\u96c6\u91ca\u653e\uff0c\u72ec\u7acb\u50a8\u80fd\u9700\u6c42\u663e\u8457\u63d0\u5347.pdf",
"provider": "vendor",
"permission": "only_me",
"data_source_type": "upload_file",
"indexing_technique": "high_quality",
"app_count": 0,
"document_count": 100,
"word_count": 1425132,
"created_by": "9eb173b9-f320-47c1-893d-836d082bf16d",
"created_at": 1761011029,
"updated_by": "9eb173b9-f320-47c1-893d-836d082bf16d",
"updated_at": 1761011084,
"embedding_model": "dengcao/Qwen3-Embedding-0.6B:F16",
"embedding_model_provider": "langgenius/ollama/ollama",
"embedding_available": true,
"retrieval_model_dict": {
"search_method": "semantic_search",
"reranking_enable": false,
"reranking_mode": null,
"reranking_model": {
"reranking_provider_name": "",
"reranking_model_name": ""
},
"weights": null,
"top_k": 3,
"score_threshold_enabled": false,
"score_threshold": 0.5
},
"tags": [],
"doc_form": "text_model",
"external_knowledge_info": {
"external_knowledge_id": null,
"external_knowledge_api_id": null,
"external_knowledge_api_name": null,
"external_knowledge_api_endpoint": null
},
"external_retrieval_model": {
"top_k": 3,
"score_threshold": 0.5,
"score_threshold_enabled": false
},
"doc_metadata": [],
"built_in_field_enabled": false,
"pipeline_id": null,
"runtime_mode": "general",
"chunk_structure": null,
"icon_info": {
"icon_type": "emoji",
"icon": "",
"icon_background": "",
"icon_url": null
},
"is_published": false,
"total_documents": 100,
"total_available_documents": 100,
"enable_api": true,
"partial_member_list": []
}
],
"has_more": false,
"limit": 30,
"total": 4,
"page": 1
}

Actual Behavior

Response:
{
"message": "Internal Server Error",
"code": "unknown",
"status": 500
}
Check dify-api log:
Exception on /v1/datasets [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_restx/api.py", line 402, 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_restx/resource.py", line 41, in dispatch_request
resp = meth(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/app/api/controllers/service_api/wraps.py", line 244, in decorated
.one_or_none()
^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/query.py", line 2785, 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 1446, in one_or_none
return self._only_one_row(
^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py", line 813, in _only_one_row
raise exc.MultipleResultsFound(
sqlalchemy.exc.MultipleResultsFound: Multiple rows were found when one or none was required

Originally created by @zhaoyinlong123 on GitHub (Nov 19, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.9.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Call the Dify knowledge base API: /v1/datasets, Request parameters: { "page": 1, "limit": 10 } ### ✔️ Expected Behavior { "data": [ { "id": "b433b138-6b10-4241-b81e-c2dce1e1d79d", "name": "\u96c6\u56e2\u5b89\u5168\u5236\u5ea6", "description": "useful for when you want to answer queries about the QBCU YG243007-2024 \u4e2d\u56fd\u8054\u901a\u7535\u4fe1\u5361\u6570\u636e\u5b89\u5168\u7ba1\u7406\u529e\u6cd5V1.0.pdf", "provider": "vendor", "permission": "only_me", "data_source_type": "upload_file", "indexing_technique": "high_quality", "app_count": 1, "document_count": 39, "word_count": 268757, "created_by": "9eb173b9-f320-47c1-893d-836d082bf16d", "created_at": 1762307769, "updated_by": "9eb173b9-f320-47c1-893d-836d082bf16d", "updated_at": 1762310028, "embedding_model": "bge-m3:latest", "embedding_model_provider": "langgenius\/ollama\/ollama", "embedding_available": true, "retrieval_model_dict": { "search_method": "semantic_search", "reranking_enable": false, "reranking_mode": "weighted_score", "reranking_model": { "reranking_provider_name": "", "reranking_model_name": "" }, "weights": { "weight_type": "customized", "keyword_setting": { "keyword_weight": 0.3 }, "vector_setting": { "vector_weight": 0.7, "embedding_model_name": "dengcao\/Qwen3-Embedding-0.6B:F16", "embedding_provider_name": "langgenius\/ollama\/ollama" } }, "top_k": 5, "score_threshold_enabled": false, "score_threshold": 0.0 }, "tags": [], "doc_form": "text_model", "external_knowledge_info": { "external_knowledge_id": null, "external_knowledge_api_id": null, "external_knowledge_api_name": null, "external_knowledge_api_endpoint": null }, "external_retrieval_model": { "top_k": 5, "score_threshold": 0.0, "score_threshold_enabled": false }, "doc_metadata": [], "built_in_field_enabled": false, "pipeline_id": null, "runtime_mode": "general", "chunk_structure": null, "icon_info": { "icon_type": "emoji", "icon": "", "icon_background": "", "icon_url": null }, "is_published": false, "total_documents": 39, "total_available_documents": 1, "enable_api": true, "partial_member_list": [] }, { "id": "6da76311-9251-459c-b36e-a78b00461ec8", "name": "Network security knowledge", "description": "", "provider": "vendor", "permission": "all_team_members", "data_source_type": "upload_file", "indexing_technique": "high_quality", "app_count": 2, "document_count": 1, "word_count": 3083, "created_by": "a1f1611b-d7b6-48a3-ba56-4582d12bb1b1", "created_at": 1761899329, "updated_by": "a1f1611b-d7b6-48a3-ba56-4582d12bb1b1", "updated_at": 1762331189, "embedding_model": "dengcao\/Qwen3-Embedding-0.6B:F16", "embedding_model_provider": "langgenius\/ollama\/ollama", "embedding_available": true, "retrieval_model_dict": { "search_method": "hybrid_search", "reranking_enable": false, "reranking_mode": "weighted_score", "reranking_model": { "reranking_provider_name": "", "reranking_model_name": "" }, "weights": { "weight_type": "customized", "keyword_setting": { "keyword_weight": 0.3 }, "vector_setting": { "vector_weight": 0.7, "embedding_model_name": "dengcao\/Qwen3-Embedding-0.6B:F16", "embedding_provider_name": "langgenius\/ollama\/ollama" } }, "top_k": 3, "score_threshold_enabled": true, "score_threshold": 0.5 }, "tags": [], "doc_form": "hierarchical_model", "external_knowledge_info": { "external_knowledge_id": null, "external_knowledge_api_id": null, "external_knowledge_api_name": null, "external_knowledge_api_endpoint": null }, "external_retrieval_model": { "top_k": 3, "score_threshold": 0.5, "score_threshold_enabled": true }, "doc_metadata": [], "built_in_field_enabled": false, "pipeline_id": null, "runtime_mode": "general", "chunk_structure": null, "icon_info": { "icon_type": "emoji", "icon": "", "icon_background": "", "icon_url": null }, "is_published": false, "total_documents": 1, "total_available_documents": 1, "enable_api": true, "partial_member_list": [] }, { "id": "8f214295-3d0f-43e9-aee2-d2cab2d2366e", "name": "Security rules and regulations", "description": "", "provider": "vendor", "permission": "all_team_members", "data_source_type": "upload_file", "indexing_technique": "high_quality", "app_count": 2, "document_count": 5, "word_count": 47627, "created_by": "a1f1611b-d7b6-48a3-ba56-4582d12bb1b1", "created_at": 1761878571, "updated_by": "a1f1611b-d7b6-48a3-ba56-4582d12bb1b1", "updated_at": 1762331179, "embedding_model": "dengcao\/Qwen3-Embedding-0.6B:F16", "embedding_model_provider": "langgenius\/ollama\/ollama", "embedding_available": true, "retrieval_model_dict": { "search_method": "hybrid_search", "reranking_enable": false, "reranking_mode": "weighted_score", "reranking_model": { "reranking_provider_name": "", "reranking_model_name": "" }, "weights": { "weight_type": "customized", "keyword_setting": { "keyword_weight": 0.3 }, "vector_setting": { "vector_weight": 0.7, "embedding_model_name": "dengcao\/Qwen3-Embedding-0.6B:F16", "embedding_provider_name": "langgenius\/ollama\/ollama" } }, "top_k": 3, "score_threshold_enabled": true, "score_threshold": 0.5 }, "tags": [], "doc_form": "hierarchical_model", "external_knowledge_info": { "external_knowledge_id": null, "external_knowledge_api_id": null, "external_knowledge_api_name": null, "external_knowledge_api_endpoint": null }, "external_retrieval_model": { "top_k": 3, "score_threshold": 0.5, "score_threshold_enabled": true }, "doc_metadata": [], "built_in_field_enabled": false, "pipeline_id": null, "runtime_mode": "general", "chunk_structure": null, "icon_info": { "icon_type": "emoji", "icon": "", "icon_background": "", "icon_url": null }, "is_published": false, "total_documents": 5, "total_available_documents": 5, "enable_api": true, "partial_member_list": [] }, { "id": "b69a96a6-2bdb-48e5-8fd7-aa9b829a8df5", "name": "\u50a8\u80fd\u7814\u62a5", "description": "useful for when you want to answer queries about the 20250811-\u534e\u5b89\u8bc1\u5238-\u534e\u5b89\u8bc1\u5238\u7535\u529b\u8bbe\u5907\u884c\u4e1a\u5468\u62a5\uff1a\u6d77\u98ce\u9879\u76ee\u5bc6\u96c6\u91ca\u653e\uff0c\u72ec\u7acb\u50a8\u80fd\u9700\u6c42\u663e\u8457\u63d0\u5347.pdf", "provider": "vendor", "permission": "only_me", "data_source_type": "upload_file", "indexing_technique": "high_quality", "app_count": 0, "document_count": 100, "word_count": 1425132, "created_by": "9eb173b9-f320-47c1-893d-836d082bf16d", "created_at": 1761011029, "updated_by": "9eb173b9-f320-47c1-893d-836d082bf16d", "updated_at": 1761011084, "embedding_model": "dengcao\/Qwen3-Embedding-0.6B:F16", "embedding_model_provider": "langgenius\/ollama\/ollama", "embedding_available": true, "retrieval_model_dict": { "search_method": "semantic_search", "reranking_enable": false, "reranking_mode": null, "reranking_model": { "reranking_provider_name": "", "reranking_model_name": "" }, "weights": null, "top_k": 3, "score_threshold_enabled": false, "score_threshold": 0.5 }, "tags": [], "doc_form": "text_model", "external_knowledge_info": { "external_knowledge_id": null, "external_knowledge_api_id": null, "external_knowledge_api_name": null, "external_knowledge_api_endpoint": null }, "external_retrieval_model": { "top_k": 3, "score_threshold": 0.5, "score_threshold_enabled": false }, "doc_metadata": [], "built_in_field_enabled": false, "pipeline_id": null, "runtime_mode": "general", "chunk_structure": null, "icon_info": { "icon_type": "emoji", "icon": "", "icon_background": "", "icon_url": null }, "is_published": false, "total_documents": 100, "total_available_documents": 100, "enable_api": true, "partial_member_list": [] } ], "has_more": false, "limit": 30, "total": 4, "page": 1 } ### ❌ Actual Behavior Response: { "message": "Internal Server Error", "code": "unknown", "status": 500 } Check dify-api log: Exception on /v1/datasets [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_restx/api.py", line 402, 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_restx/resource.py", line 41, in dispatch_request resp = meth(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/service_api/wraps.py", line 244, in decorated .one_or_none() ^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/query.py", line 2785, 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 1446, in one_or_none return self._only_one_row( ^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py", line 813, in _only_one_row raise exc.MultipleResultsFound( sqlalchemy.exc.MultipleResultsFound: Multiple rows were found when one or none was required
yindo added the 🐞 bug label 2026-02-21 20:07:23 -05:00
yindo closed this issue 2026-02-21 20:07:23 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 19, 2025):

Hi @zhaoyinlong123! I'm Dosu and I’m helping the dify team.

The 500 Internal Server Error is caused by a SQLAlchemy MultipleResultsFound exception in the validate_dataset_token decorator. This happens because the query expects only one owner record per tenant in the TenantAccountJoin table, but multiple owner entries exist for the same tenant, violating that assumption. The error occurs before the dataset retrieval logic runs.

To resolve this, check your TenantAccountJoin table for duplicate owner records for the same tenant and remove any extras. You can do this with a SQL query like:

SELECT tenant_id, COUNT(*) 
FROM tenant_account_join 
WHERE role = 'owner' 
GROUP BY tenant_id 
HAVING COUNT(*) > 1;

Then, delete the extra owner rows for each affected tenant, leaving only one owner per tenant.

For a long-term fix, consider enforcing a unique constraint on (tenant_id, role) in the TenantAccountJoin table to prevent multiple owners, or update the code to use .first() instead of .one_or_none() if multiple owners are acceptable in your use case. See the relevant code and comments for more details "here".

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Nov 19, 2025): <!-- Greeting --> Hi @zhaoyinlong123! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify team. <!-- Answer --> The 500 Internal Server Error is caused by a SQLAlchemy MultipleResultsFound exception in the validate_dataset_token decorator. This happens because the query expects only one owner record per tenant in the TenantAccountJoin table, but multiple owner entries exist for the same tenant, violating that assumption. The error occurs before the dataset retrieval logic runs. To resolve this, check your TenantAccountJoin table for duplicate owner records for the same tenant and remove any extras. You can do this with a SQL query like: ```sql SELECT tenant_id, COUNT(*) FROM tenant_account_join WHERE role = 'owner' GROUP BY tenant_id HAVING COUNT(*) > 1; ``` Then, delete the extra owner rows for each affected tenant, leaving only one owner per tenant. For a long-term fix, consider enforcing a unique constraint on (tenant_id, role) in the TenantAccountJoin table to prevent multiple owners, or update the code to use .first() instead of .one_or_none() if multiple owners are acceptable in your use case. See the relevant code and comments for more details ["here"](https://github.com/langgenius/dify/blob/88c9b18cb679cc037be68ac5f168c6bc28809889/api/controllers/service_api/wraps.py#L216-L282). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/e0295641-3f35-4d6c-9f60-00704d660e2d?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/e0295641-3f35-4d6c-9f60-00704d660e2d?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/e0295641-3f35-4d6c-9f60-00704d660e2d?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/e0295641-3f35-4d6c-9f60-00704d660e2d?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/e0295641-3f35-4d6c-9f60-00704d660e2d?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/e0295641-3f35-4d6c-9f60-00704d660e2d?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/e0295641-3f35-4d6c-9f60-00704d660e2d?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/28409)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#20420