mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 06:44:27 +01:00
error message when impossible to infer the primary-key; fix #517
This commit is contained in:
parent
c25641ff2d
commit
4ccf1d10bd
@ -145,7 +145,7 @@ async fn update_multiple_documents(mut ctx: Request<Data>, is_partial: bool) ->
|
|||||||
Some(id) => id,
|
Some(id) => id,
|
||||||
None => match data.first().and_then(|docs| find_primary_key(docs)) {
|
None => match data.first().and_then(|docs| find_primary_key(docs)) {
|
||||||
Some(id) => id,
|
Some(id) => id,
|
||||||
None => return Err(ResponseError::bad_request("Could not infer a schema")),
|
None => return Err(ResponseError::bad_request("Could not infer a primary key")),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -205,6 +205,11 @@ impl Server {
|
|||||||
self.post_request_async(&url, body);
|
self.post_request_async(&url, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_or_replace_multiple_documents_sync(&mut self, body: Value) -> (Value, StatusCode) {
|
||||||
|
let url = format!("/indexes/{}/documents", self.uid);
|
||||||
|
self.post_request(&url, body)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_or_update_multiple_documents(&mut self, body: Value) {
|
pub fn add_or_update_multiple_documents(&mut self, body: Value) {
|
||||||
let url = format!("/indexes/{}/documents", self.uid);
|
let url = format!("/indexes/{}/documents", self.uid);
|
||||||
self.put_request_async(&url, body);
|
self.put_request_async(&url, body);
|
||||||
|
@ -625,3 +625,36 @@ fn create_index_without_primary_key_and_search() {
|
|||||||
assert_eq!(status_code, 200);
|
assert_eq!(status_code, 200);
|
||||||
assert_eq!(response["hits"].as_array().unwrap().len(), 0);
|
assert_eq!(response["hits"].as_array().unwrap().len(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test the error message when we push an document update and impossibility to find primary key
|
||||||
|
// Test issue https://github.com/meilisearch/MeiliSearch/issues/517
|
||||||
|
#[test]
|
||||||
|
fn check_add_documents_without_primary_key() {
|
||||||
|
let mut server = common::Server::with_uid("movies");
|
||||||
|
|
||||||
|
// 1 - Create the index with no primary_key
|
||||||
|
|
||||||
|
let body = json!({
|
||||||
|
"uid": "movies",
|
||||||
|
});
|
||||||
|
let (response, status_code) = server.create_index(body);
|
||||||
|
assert_eq!(status_code, 201);
|
||||||
|
assert_eq!(response["primaryKey"], json!(null));
|
||||||
|
|
||||||
|
// 2- Add document
|
||||||
|
|
||||||
|
let body = json!([{
|
||||||
|
"title": "Test",
|
||||||
|
"comment": "comment test"
|
||||||
|
}]);
|
||||||
|
|
||||||
|
let (response, status_code) = server.add_or_replace_multiple_documents_sync(body);
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"message": "Could not infer a primary key"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(status_code, 400);
|
||||||
|
assert_json_eq!(response, expected, ordered: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user