mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-05 04:28:55 +01:00
Merge #247
247: Return a `MissingDocumentId` error when a document doesn't have one r=Kerollmops a=Kerollmops We were wrongly returning a `MissingPrimaryKey` instead of a `MissingDocumentId` error for when a document was missing a document id. We also improved the error message for when a document id is invalid (wrong type or wrong format). Co-authored-by: Kerollmops <clement@meilisearch.com>
This commit is contained in:
commit
ca9fa329d1
@ -206,7 +206,13 @@ impl fmt::Display for UserError {
|
|||||||
Self::InvalidCriterionName { name } => write!(f, "invalid criterion {}", name),
|
Self::InvalidCriterionName { name } => write!(f, "invalid criterion {}", name),
|
||||||
Self::InvalidDocumentId { document_id } => {
|
Self::InvalidDocumentId { document_id } => {
|
||||||
let json = serde_json::to_string(document_id).unwrap();
|
let json = serde_json::to_string(document_id).unwrap();
|
||||||
write!(f, "document identifier is invalid {}", json)
|
write!(
|
||||||
|
f,
|
||||||
|
"document identifier is invalid {}, \
|
||||||
|
a document id can be of type integer or string \
|
||||||
|
only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and underscores (_)",
|
||||||
|
json
|
||||||
|
)
|
||||||
}
|
}
|
||||||
Self::InvalidFilterAttribute(error) => error.fmt(f),
|
Self::InvalidFilterAttribute(error) => error.fmt(f),
|
||||||
Self::MissingDocumentId { document } => {
|
Self::MissingDocumentId { document } => {
|
||||||
|
@ -18,7 +18,7 @@ use crate::index::db_name;
|
|||||||
use crate::update::index_documents::merge_function::{keep_latest_obkv, merge_obkvs};
|
use crate::update::index_documents::merge_function::{keep_latest_obkv, merge_obkvs};
|
||||||
use crate::update::{AvailableDocumentsIds, UpdateIndexingStep};
|
use crate::update::{AvailableDocumentsIds, UpdateIndexingStep};
|
||||||
use crate::{
|
use crate::{
|
||||||
ExternalDocumentsIds, FieldId, FieldDistribution, FieldsIdsMap, Index, MergeFn, Result, BEU32,
|
ExternalDocumentsIds, FieldDistribution, FieldId, FieldsIdsMap, Index, MergeFn, Result, BEU32,
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_PRIMARY_KEY_NAME: &str = "id";
|
const DEFAULT_PRIMARY_KEY_NAME: &str = "id";
|
||||||
@ -190,7 +190,7 @@ impl Transform<'_, '_> {
|
|||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
if !self.autogenerate_docids {
|
if !self.autogenerate_docids {
|
||||||
return Err(UserError::MissingPrimaryKey.into());
|
return Err(UserError::MissingDocumentId { document }.into());
|
||||||
}
|
}
|
||||||
let uuid = uuid::Uuid::new_v4().to_hyphenated().encode_lower(&mut uuid_buffer);
|
let uuid = uuid::Uuid::new_v4().to_hyphenated().encode_lower(&mut uuid_buffer);
|
||||||
Cow::Borrowed(uuid)
|
Cow::Borrowed(uuid)
|
||||||
|
Loading…
Reference in New Issue
Block a user