Merge pull request #91 from meilisearch/add-primary-key-to-fields-map

add primary key to fields_id_map when not present
This commit is contained in:
Clément Renault 2021-03-01 16:20:41 +01:00 committed by GitHub
commit 794fce7bff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -516,7 +516,7 @@ fn compute_primary_key_pair(
) -> anyhow::Result<(FieldId, String)> { ) -> anyhow::Result<(FieldId, String)> {
match primary_key { match primary_key {
Some(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())) Ok((id, primary_key.to_string()))
} }
None => { None => {
@ -572,17 +572,6 @@ mod test {
use super::compute_primary_key_pair; use super::compute_primary_key_pair;
use super::FieldsIdsMap; 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] #[test]
fn should_return_primary_key_if_is_some() { fn should_return_primary_key_if_is_some() {
let mut fields_map = FieldsIdsMap::new(); let mut fields_map = FieldsIdsMap::new();