mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 11:57:07 +02:00
fix missing primary key
This commit is contained in:
parent
ac63f1cd7a
commit
99e8d4adae
5 changed files with 20 additions and 7 deletions
|
@ -156,7 +156,7 @@ async fn update_multiple_documents(
|
|||
let mut schema = index
|
||||
.main
|
||||
.schema(&reader)?
|
||||
.ok_or(Error::internal("Impossible to retrieve the schema"))?;
|
||||
.ok_or(meilisearch_core::Error::SchemaMissing)?;
|
||||
|
||||
if schema.primary_key().is_none() {
|
||||
let id = match ¶ms.primary_key {
|
||||
|
@ -164,7 +164,7 @@ async fn update_multiple_documents(
|
|||
None => body
|
||||
.first()
|
||||
.and_then(find_primary_key)
|
||||
.ok_or(Error::bad_request("Could not infer a primary key"))?,
|
||||
.ok_or(meilisearch_core::Error::MissingPrimaryKey)?
|
||||
};
|
||||
|
||||
schema
|
||||
|
|
|
@ -92,7 +92,7 @@ async fn max_field_limit_exceeded_error() {
|
|||
}
|
||||
let docs = json!([doc]);
|
||||
assert_error_async!(
|
||||
"max_field_limit_exceeded",
|
||||
"max_fields_limit_exceeded",
|
||||
"invalid_request_error",
|
||||
server,
|
||||
server.add_or_replace_multiple_documents_sync(docs).await);
|
||||
|
@ -180,3 +180,17 @@ async fn payload_too_large_error() {
|
|||
StatusCode::PAYLOAD_TOO_LARGE,
|
||||
server.create_index(json!(bigvec)).await);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn missing_primary_key_error() {
|
||||
let mut server = common::Server::with_uid("test");
|
||||
server.create_index(json!({"uid": "test"})).await;
|
||||
let document = json!([{
|
||||
"content": "test"
|
||||
}]);
|
||||
assert_error!(
|
||||
"missing_primary_key",
|
||||
"invalid_request_error",
|
||||
StatusCode::BAD_REQUEST,
|
||||
server.add_or_replace_multiple_documents_sync(document).await);
|
||||
}
|
||||
|
|
|
@ -658,9 +658,8 @@ async fn check_add_documents_without_primary_key() {
|
|||
|
||||
let (response, status_code) = server.add_or_replace_multiple_documents_sync(body).await;
|
||||
|
||||
let message = response["message"].as_str().unwrap();
|
||||
assert_eq!(response.as_object().unwrap().len(), 4);
|
||||
assert_eq!(message, "Could not infer a primary key");
|
||||
assert_eq!(response["errorCode"], "missing_primary_key");
|
||||
assert_eq!(status_code, 400);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue