Skip to content

Commit c838d91

Browse files
WaylandYangWayland Yangclaude
authored
A tombstone pushed to an api source with an external_id no longer needs a filename, so {"external_id":"note-7","deleted":true} marks the document missing instead of being rejected (#1487)
Co-authored-by: Wayland Yang <wayland@WaylanddeMacBook-Pro.local> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 15a2df1 commit c838d91

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎crates/utopia-server/src/api/sources_routes.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ pub async fn sync_now(
413413

414414
#[derive(Deserialize)]
415415
pub struct IngestBody {
416+
/// 墓碑带着 external_id 时用不上文件名(身份是 external_id),缺了也收;
417+
/// 其余情况仍然必填,空串在下面的校验里挡
418+
#[serde(default)]
416419
pub filename: String,
417420
/// 墓碑推送(`deleted: true`)可以不带 content——指南一直这么写,而字段
418421
/// 从前是必填,缺了就在反序列化那一步被拒。其余情况仍然必填:空串在

‎crates/utopia-server/src/api/sources_statements_tests.rs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,42 @@ async fn a_tombstone_marks_the_item_missing_and_a_new_push_revives_it() -> anyho
595595
f.cleanup().await
596596
}
597597

598+
/// api 来源的墓碑按 external_id 认身份,不用再带文件名;正常推送缺文件名照旧不收
599+
#[tokio::test]
600+
async fn an_api_tombstone_needs_only_its_external_id() -> anyhow::Result<()> {
601+
let Some(f) = Fixture::new().await? else {
602+
return Ok(());
603+
};
604+
let (status, body) = f
605+
.push_api(&json!({ "filename": "note-7.md", "content": "Kitchen inventory.", "external_id": "note-7" }))
606+
.await?;
607+
assert_eq!(status, StatusCode::OK, "{body}");
608+
let (status, body) = f
609+
.push_api(&json!({ "external_id": "note-7", "deleted": true }))
610+
.await?;
611+
assert_eq!(status, StatusCode::OK, "{body}");
612+
assert_eq!(body["action"], "marked_missing");
613+
// 回复对没推过的 id 也是 marked_missing,所以要看文档本身真的标了
614+
let doc = documents::find_by_external_key(&f.pool, f.api_source, "api:note-7")
615+
.await?
616+
.expect("the tombstone marks the document, it does not delete it");
617+
let (missing,): (bool,) =
618+
sqlx::query_as("SELECT missing_since IS NOT NULL FROM documents WHERE id = $1")
619+
.bind(doc.id)
620+
.fetch_one(&f.pool)
621+
.await?;
622+
assert!(missing, "api:note-7 is marked missing");
623+
let (status, body) = f
624+
.push_api(&json!({ "content": "Kitchen inventory.", "external_id": "note-8" }))
625+
.await?;
626+
assert_ne!(
627+
status,
628+
StatusCode::OK,
629+
"a push with content still needs its filename: {body}"
630+
);
631+
f.cleanup().await
632+
}
633+
598634
/// 密钥的查看和轮换对 `statements` 来源和 `api` 来源一样可用:创建时给过一次的密钥
599635
/// 之后还查得到,轮换后旧密钥立刻失效、新密钥能推。端到端跑服务时抓到的:这两个接口
600636
/// 原来只认 `api`

‎web/src/docs/ingest.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Content-Type: application/json
9595

9696
| Field | Required | Meaning |
9797
|---|---|---|
98-
| `filename` | yes | Display name; also the fallback identity when `external_id` is absent. |
98+
| `filename` | yes* | Display name; also the fallback identity when `external_id` is absent. *Optional on a tombstone that has `external_id`.* |
9999
| `content` | yes* | Full text. *Optional when `deleted` is `true`.* |
100100
| `doc_time` | no | RFC 3339; the document's position on the time axis. |
101101
| `external_id` | no | Stable identity. Same identity + new content → update in place. Without it, `filename` is the identity. |

0 commit comments

Comments
 (0)