bug(lib): ignore primary if already set on document addition

This commit is contained in:
Marin Postma 2021-12-15 10:07:47 +01:00
parent 5af51c852c
commit d534a7f7c8
2 changed files with 26 additions and 1 deletions

View File

@ -1032,3 +1032,26 @@ async fn error_primary_key_inference() {
assert_eq!(response["error"], expected_error);
}
#[actix_rt::test]
async fn add_documents_with_primary_key_twice() {
let server = Server::new().await;
let index = server.index("test");
let documents = json!([
{
"title": "11",
"desc": "foobar"
}
]);
index.add_documents(documents.clone(), Some("title")).await;
index.wait_task(0).await;
let (response, _code) = index.get_task(0).await;
assert_eq!(response["status"], "succeeded");
index.add_documents(documents, Some("title")).await;
index.wait_task(1).await;
let (response, _code) = index.get_task(1).await;
assert_eq!(response["status"], "succeeded");
}

View File

@ -237,8 +237,10 @@ impl Index {
let mut txn = self.write_txn()?;
if let Some(primary_key) = primary_key {
if self.primary_key(&txn)?.is_none() {
self.update_primary_key_txn(&mut txn, primary_key)?;
}
}
let indexing_callback = |indexing_step| debug!("update: {:?}", indexing_step);