ValueError: Credential record not found.

用户使用 Dify 1.15.0 自托管版本(Source 部署),在管理台执行 DELETE /console/api/workspaces/current/model-providers/langgenius/xinference/xinference/models/credentials 操作

ValueError: Credential record not found.

ValueError: Credential record not found.

快速结论:该报错发生在 Dify 自托管环境下,删除 Xinference 模型凭证时触发,核心原因是前端未能正确提交 modelmodel_type 字段,导致数据库查询时无法匹配已有记录。优先排查 Xinference 模型凭证的添加/删除流程,并检查数据库中是否存在不完整的凭证记录。

问题场景

用户使用 Dify 1.15.0 自托管版本(Source 部署),在管理台执行 DELETE /console/api/workspaces/current/model-providers/langgenius/xinference/xinference/models/credentials 操作时触发报错。该操作通过前端 UI 发起,旨在删除已配置的 Xinference 模型凭证。

报错原文

2026-07-02 22:06:28,880 ERROR [external_api.py:92] 1adb1ede26 value_error in request handler
...
File "/home/leslie/share/code/dify/api/services/model_provider_service.py", line 368, in remove_model_credential
...
ValueError: Credential record not found.

(完整报错包含从 full_dispatch_requestremove_model_credential 的调用链,最终抛出的异常即为 ValueError: Credential record not found.

原因分析

最可能的原因是:Xinference 凭证表单存在前端 Bug,导致添加凭证时 modelmodel_type 字段未被正确提交。删除凭证时,后端 delete_custom_model_credential 方法(位于 api/core/entities/provider_configuration.py 第 1182-1191 行)会使用复合过滤条件(credential_idtenant_idprovider_namemodel_name 以及 model_type)进行查询。由于初始添加时缺失了 model/model_type,导致删除时的查询条件与存储的记录不匹配,从而无法找到凭证记录。

用户同时报告的另一个 Issue(#38319)进一步确认了该根因:添加 Xinference 凭证时,前端未在请求中包含 modelmodel_type 字段。

环境排查

  • Dify 版本:1.15.0(自托管源代码部署)
  • Python 版本:3.12(由报错路径 .venv/lib/python3.12/site-packages/ 推断)
  • Flask 版本:由报错路径推断,应使用 Flask 及其扩展框架 Flask-RESTx
  • 数据库:Dify 默认使用的 PostgreSQL 或 MySQL(需要确认 provider_model_credentials 表存在)
  • 凭据提供方:Xinference(langgenius/xinference 模型提供商)

解决步骤

  1. 检查数据库中的异常记录:连接到 Dify 数据库,执行以下 SQL 查找 Xinference 相关的凭证记录,特别关注 model_namemodel_type 字段是否为空或异常:
    SELECT * FROM provider_model_credentials WHERE provider_name LIKE '%xinference%';
  2. 手动删除异常凭证:如果找到不完整的记录,通过其 id 直接删除:
    DELETE FROM provider_model_credentials WHERE id = '<the_id>';
  3. 确认前端 Bug 修复:验证 Xinference 凭证表单在添加时是否能正确提交 modelmodel_type 字段。若仍缺失,可优先尝试升级 Dify 到包含该修复的版本。
  4. 重新添加凭证:在数据库清理完成后,通过前端 UI 重新添加 Xinference 凭证,确保所有必填字段已完整填写。

注意:由于根本原因是前端 Bug,手动删除只是临时解决办法。可优先尝试寻找 Dify 社区或官方针对 #38319 的修复补丁。

验证方法

在清理数据库并重新添加凭证后,尝试通过前端 UI 执行同步删除操作(例如,在管理台删除该模型凭证),确保返回 HTTP 200 而非 400,且不再出现 ValueError: Credential record not found. 异常。同时检查 provider_model_credentials 表中对应的记录已被正常删除。

参考来源

langgenius/dify #38333

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

celebrityanime
celebrityanime
文章: 11448

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注