SuperAPI AI 工具集

frappe-errors-serverscripts

编程与开发

查看项目

更新于 10-15 22:17

技能介绍

用途:在 Frappe 中调试或预防 Server Scripts 报错,按错误信息给出原因与修复方式。

主要能力:提供错误诊断流程,包括 ImportError/NameError(沙箱禁止 import,仅 json 可导入)、SyntaxError(尝试 try/except、raise、exec/eval 被 RestrictedPython 阻止)、脚本未执行(脚本类型、DocType、事件或启用状态选错)、403 权限、Scheduler 未提交数据、API 返回空响应、超时等。附错误信息到原因与修复的对照表,以及沙箱可用的 frappe API 分类参考(Document、Database、Query Builder、HTTP、Utility、User/Session、Messages)。

必要用法:Frappe v15 起 Server Scripts 默认禁用,需在 site_config.json 设置 { "server_script_enabled": 1 };Frappe Cloud 仅在私有 bench 可用。用 frappe.parse_json() 替代 json.loads,用 frappe.utils 函数替代 datetime,用 frappe.throw() 替代 raise,用条件判断替代 try/except。Scheduler 脚本必须调用 frappe.db.commit() 并给查询加 limit;API 脚本必须设置 frappe.response["message"];doc 仅在 Document Event 中可用。

适用场景:处理 Document Event、API、Scheduler Event、Permission Query 四类脚本的报错与防御性写法。

限制:沙箱阻止 import、try/except 与 raise;Before Save 中调用 doc.save() 会导致递归;SQL 涉及用户输入须用 frappe.db.escape() 或参数化查询。其他平台细节与收费信息暂未提供。