diff --git a/meilisearch-types/src/deserr/mod.rs b/meilisearch-types/src/deserr/mod.rs index 462b356ab..87ca342d7 100644 --- a/meilisearch-types/src/deserr/mod.rs +++ b/meilisearch-types/src/deserr/mod.rs @@ -151,11 +151,14 @@ make_missing_field_convenience_builder!(MissingApiKeyExpiresAt, missing_api_key_ make_missing_field_convenience_builder!(MissingApiKeyIndexes, missing_api_key_indexes); make_missing_field_convenience_builder!(MissingSwapIndexes, missing_swap_indexes); make_missing_field_convenience_builder!(MissingDocumentFilter, missing_document_filter); -make_missing_field_convenience_builder!(MissingDocumentFilter, missing_document_edition_function); make_missing_field_convenience_builder!( MissingFacetSearchFacetName, missing_facet_search_facet_name ); +make_missing_field_convenience_builder!( + MissingDocumentEditionFunction, + missing_document_edition_function +); // Integrate a sub-error into a [`DeserrError`] by taking its error message but using // the default error code (C) from `Self` diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index 3e1316955..092d852ac 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -224,6 +224,7 @@ InvalidDocumentCsvDelimiter , InvalidRequest , BAD_REQUEST ; InvalidDocumentFields , InvalidRequest , BAD_REQUEST ; InvalidDocumentRetrieveVectors , InvalidRequest , BAD_REQUEST ; MissingDocumentFilter , InvalidRequest , BAD_REQUEST ; +MissingDocumentEditionFunction , InvalidRequest , BAD_REQUEST ; InvalidDocumentFilter , InvalidRequest , BAD_REQUEST ; InvalidDocumentGeoField , InvalidRequest , BAD_REQUEST ; InvalidVectorDimensions , InvalidRequest , BAD_REQUEST ; diff --git a/meilisearch/src/routes/indexes/documents.rs b/meilisearch/src/routes/indexes/documents.rs index 412ac8e47..20c0aed07 100644 --- a/meilisearch/src/routes/indexes/documents.rs +++ b/meilisearch/src/routes/indexes/documents.rs @@ -24,7 +24,7 @@ use meilisearch_types::{milli, Document, Index}; use mime::Mime; use once_cell::sync::Lazy; use serde::Deserialize; -use serde_json::{Map, Value}; +use serde_json::Value; use tempfile::tempfile; use tokio::fs::File; use tokio::io::{AsyncSeekExt, AsyncWriteExt, BufWriter}; @@ -629,7 +629,7 @@ pub async fn edit_documents_by_function( filter_expr: filter, context: match context { Some(Value::Object(m)) => Some(m), - None => Some(Map::default()), + None => None, _ => { return Err(ResponseError::from_msg( "The context must be an object".to_string(), diff --git a/milli/src/update/index_documents/mod.rs b/milli/src/update/index_documents/mod.rs index 0baf63bb1..271d4037c 100644 --- a/milli/src/update/index_documents/mod.rs +++ b/milli/src/update/index_documents/mod.rs @@ -216,11 +216,11 @@ where let mut documents_batch_builder = tempfile::tempfile().map(DocumentsBatchBuilder::new)?; let mut documents_to_remove = RoaringBitmap::new(); - let context: Dynamic = match context { + let context: Option = match context { Some(context) => { - serde_json::from_value(context.into()).map_err(InternalError::SerdeJson)? + Some(serde_json::from_value(context.into()).map_err(InternalError::SerdeJson)?) } - None => Dynamic::from(()), + None => None, }; enum DocumentEdition { @@ -244,7 +244,9 @@ where let document_id = &json_document[primary_key]; let mut scope = Scope::new(); - scope.push_constant_dynamic("context", context.clone()); + if let Some(context) = context.as_ref().cloned() { + scope.push_constant_dynamic("context", context.clone()); + } scope.push("doc", rhai_document); // That's were the magic happens. We run the user script // which edits "doc" scope variable reprensenting the document diff --git a/milli/src/update/index_documents/parallel.rs b/milli/src/update/index_documents/parallel.rs index 9769e8ab5..52e72a378 100644 --- a/milli/src/update/index_documents/parallel.rs +++ b/milli/src/update/index_documents/parallel.rs @@ -60,7 +60,7 @@ impl<'t> ImmutableObkvs<'t> { let name = self.fields_ids_map.name(id).ok_or( crate::error::FieldIdMapMissingEntry::FieldId { field_id: id, - process: "allobkv_to_rhaimap", + process: "all_obkv_to_rhaimap", }, )?; let value = serde_json::from_slice(value)