mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-29 16:24:26 +01:00
Merge #3608
3608: In a settings update, check to see if the primary key actually changes before erroring out r=irevoire a=GregoryConrad Previously, if the primary key was set and a Settings update contained a primary key, an error would be returned. However, this error is not needed if the new PK == the current PK. This PR just checks to see if the PK actually changes before raising an error. I came across this slight hiccup in https://github.com/GregoryConrad/mimir/issues/156#issuecomment-1484128654 Co-authored-by: Gregory Conrad <gregorysconrad@gmail.com>
This commit is contained in:
commit
31bb61ba99
@ -565,8 +565,12 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
|
|||||||
self.index.put_primary_key(self.wtxn, primary_key)?;
|
self.index.put_primary_key(self.wtxn, primary_key)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
let primary_key = self.index.primary_key(self.wtxn)?.unwrap();
|
let curr_primary_key = self.index.primary_key(self.wtxn)?.unwrap().to_string();
|
||||||
Err(UserError::PrimaryKeyCannotBeChanged(primary_key.to_string()).into())
|
if primary_key == &curr_primary_key {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(UserError::PrimaryKeyCannotBeChanged(curr_primary_key).into())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Setting::Reset => {
|
Setting::Reset => {
|
||||||
@ -1332,6 +1336,17 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
wtxn.commit().unwrap();
|
wtxn.commit().unwrap();
|
||||||
|
|
||||||
|
// Updating settings with the same primary key should do nothing
|
||||||
|
let mut wtxn = index.write_txn().unwrap();
|
||||||
|
index
|
||||||
|
.update_settings_using_wtxn(&mut wtxn, |settings| {
|
||||||
|
settings.set_primary_key(S("mykey"));
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(index.primary_key(&wtxn).unwrap(), Some("mykey"));
|
||||||
|
wtxn.commit().unwrap();
|
||||||
|
|
||||||
|
// Updating the settings with a different (or no) primary key causes an error
|
||||||
let mut wtxn = index.write_txn().unwrap();
|
let mut wtxn = index.write_txn().unwrap();
|
||||||
let error = index
|
let error = index
|
||||||
.update_settings_using_wtxn(&mut wtxn, |settings| {
|
.update_settings_using_wtxn(&mut wtxn, |settings| {
|
||||||
|
Loading…
Reference in New Issue
Block a user