From e08b6b3ec7c4329df1d6d3dcc3f3815a35b85aca Mon Sep 17 00:00:00 2001 From: mpostma Date: Fri, 19 Feb 2021 09:54:31 +0100 Subject: [PATCH] add primary key to fields_id_map when not present --- milli/src/update/index_documents/transform.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/milli/src/update/index_documents/transform.rs b/milli/src/update/index_documents/transform.rs index 68888aad9..b22cd14c6 100644 --- a/milli/src/update/index_documents/transform.rs +++ b/milli/src/update/index_documents/transform.rs @@ -516,7 +516,7 @@ fn compute_primary_key_pair( ) -> anyhow::Result<(FieldId, String)> { match primary_key { Some(primary_key) => { - let id = fields_ids_map.id(primary_key).expect("primary key must be present in the fields id map"); + let id = fields_ids_map.insert(primary_key).ok_or(anyhow!("Maximum number of fields exceeded"))?; Ok((id, primary_key.to_string())) } None => { @@ -572,17 +572,6 @@ mod test { use super::compute_primary_key_pair; use super::FieldsIdsMap; - #[test] - #[should_panic] - fn should_panic_primary_key_not_in_map() { - let mut fields_map = FieldsIdsMap::new(); - let _result = compute_primary_key_pair( - Some("toto"), - &mut fields_map, - None, - false); - } - #[test] fn should_return_primary_key_if_is_some() { let mut fields_map = FieldsIdsMap::new();