From dcdc83946fa2939ed6c446b4e434edc35f923678 Mon Sep 17 00:00:00 2001 From: JWSong Date: Tue, 25 Jun 2024 21:41:47 +0900 Subject: [PATCH] accept large number as string --- meilisearch/tests/documents/add_documents.rs | 71 ++++++++++++++++++++ milli/src/documents/primary_key.rs | 2 +- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/meilisearch/tests/documents/add_documents.rs b/meilisearch/tests/documents/add_documents.rs index b1262fa2d..49e5af95e 100644 --- a/meilisearch/tests/documents/add_documents.rs +++ b/meilisearch/tests/documents/add_documents.rs @@ -1040,6 +1040,77 @@ async fn document_addition_with_primary_key() { "###); } +#[actix_rt::test] +async fn document_addition_with_huge_int_primary_key() { + let server = Server::new().await; + let index = server.index("test"); + + let documents = json!([ + { + "primary": 14630868576586246730u64, + "content": "foo", + } + ]); + let (response, code) = index.add_documents(documents, Some("primary")).await; + snapshot!(code, @"202 Accepted"); + snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), + @r###" + { + "taskUid": 0, + "indexUid": "test", + "status": "enqueued", + "type": "documentAdditionOrUpdate", + "enqueuedAt": "[date]" + } + "###); + + index.wait_task(0).await; + + let (response, code) = index.get_task(0).await; + snapshot!(code, @"200 OK"); + snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), + @r###" + { + "uid": 0, + "indexUid": "test", + "status": "succeeded", + "type": "documentAdditionOrUpdate", + "canceledBy": null, + "details": { + "receivedDocuments": 1, + "indexedDocuments": 1 + }, + "error": null, + "duration": "[duration]", + "enqueuedAt": "[date]", + "startedAt": "[date]", + "finishedAt": "[date]" + } + "###); + + let (response, code) = index.get().await; + snapshot!(code, @"200 OK"); + snapshot!(json_string!(response, { ".createdAt" => "[date]", ".updatedAt" => "[date]" }), + @r###" + { + "uid": "test", + "createdAt": "[date]", + "updatedAt": "[date]", + "primaryKey": "primary" + } + "###); + + let (response, code) = index.get_document(14630868576586246730u64, None).await; + snapshot!(code, @"200 OK"); + snapshot!(json_string!(response), + @r###" + { + "primary": 14630868576586246730, + "content": "foo" + } + "###); +} + #[actix_rt::test] async fn replace_document() { let server = Server::new().await; diff --git a/milli/src/documents/primary_key.rs b/milli/src/documents/primary_key.rs index 29f95beaf..22918f8fc 100644 --- a/milli/src/documents/primary_key.rs +++ b/milli/src/documents/primary_key.rs @@ -166,7 +166,7 @@ pub fn validate_document_id_value(document_id: Value) -> StdResult Ok(s.to_string()), None => Err(UserError::InvalidDocumentId { document_id: Value::String(string) }), }, - Value::Number(number) if number.is_i64() => Ok(number.to_string()), + Value::Number(number) if !number.is_f64() => Ok(number.to_string()), content => Err(UserError::InvalidDocumentId { document_id: content }), } }