Datasette 1.0a27 提升安全性和插件兼容性

Simon Willison··作者 Simon Willison

关键信息

CSRF 更新遵循 Filippo Valsorda 关于基于头部的安全 CSRF 保护建议,而 RenameTableEvent 则帮助插件(如 datasette-comments)在 SQLite 事务中重命名表时做出适当反应。

资讯摘要

Datasette 1.0a27 是一个 alpha 版本,包含两项主要改进:首先,它用现代浏览器头部替代了 Django 风格的 CSRF 表单令牌,提升了安全性;其次,新增了 RenameTableEvent,在 SQLite 事务中重命名表时触发,帮助插件(如 datasette-comments)适配表名变化。其他改进包括支持内部客户端请求指定 actor 的参数、提供基于磁盘的内部数据库选项以解决锁定问题、对 upsert 操作进行更严格的校验(拒绝主键为空的行)、优化 API 文档示例,以及统一 JSON 响应格式。这些更新共同提升了开发者的可用性和维护效率。

资讯正文

<p><strong>发布:</strong> <a href="https://github.com/simonw/datasette/releases/tag/1.0a27">datasette 1.0a27</a></p>

<p>此次 Datasette 新版本的 alpha 版本包含两项重大变更。我已在昨天详细介绍了其中第一项——Datasette 不再使用 Django 风格的 CSRF 表单令牌,而是采用现代浏览器头部机制,如 Filippo Valsorda 所描述的那样 <a href="https://words.filippo.io/csrf">(CSRF)</a>。</p>

<p>第二个重要变化是,当 SQLite 事务中重命名表时,Datasette 现在会触发一个新的事件 <a href="https://docs.datasette.io/en/latest/events.html#datasette.events.RenameTableEvent">RenameTableEvent</a>。这一改进很有用,因为某些插件(例如 <a href="https://github.com/datasette/datasette-comments">datasette-comments</a>)会根据表名附加额外数据到记录中,因此表名更改后这些插件需要做出相应反应。</p>

<p>以下是该 alpha 版本中的其他更新:</p>

<blockquote>

<ul>

<li>新增 <a href="https://docs.datasette.io/en/latest/internals.html#internals-datasette-client-actor">actor= 参数</a> 至 <code>datasette.client</code> 方法,允许内部请求以特定角色身份发起。这对编写自动化测试特别有用。(<a href="https://github.com/simonw/datasette/pull/2688">#2688</a>)</li>

<li>新增 <code>Database(is_temp_disk=True)</code> 选项,用于内部数据库。这有助于解决因内部数据库存储在内存而非磁盘上而导致的间歇性数据库锁定错误。(<a href="https://github.com/simonw/datasette/issues/2683">#2683</a>)(<a href="https://github.com/simonw/datasette/pull/2684">#2684</a>)</li>

<li><code>/&lt;database&gt;/&lt;table&gt;/-/upsert</code> API(<a href="https://docs.datasette.io/en/latest/json_api.html#tableupsertview">文档</a>)现在拒绝包含 <code>null</code> 主键值的行。(<a href="https://github.com/simonw/datasette/issues/1936">#1936</a>)</li>

<li>改进了 API 探索器中 <code>/-/upsert</code> 端点的示例。(<a href="https://docs.datasette.io/en/latest/json_api.html#tableupsertview">文档</a>)。(<a href="https://github.com/simonw/datasette/issues/1936">#1936</a>)</li>

<li><code>/&lt;database&gt;.json</code> 端点现在包含一个 <code>"ok": true</code> 键,与其他 JSON API 响应保持一致。</li>

<li><a href="https://docs.datasette.io/en/latest/internals.html#internals-utils-call-with-supported-arguments">call_with_supported_arguments()</a> 现在被正式记录为受支持的公共 API。(<a href="https://github.com/simonw/datasette/pull/2678">#2678</a>)</li>

</ul>

</blockquote>

来源与参考

  1. 原始链接
  2. Release: datasette 1.0a27

收录于 2026-04-17