Explain a setting that was never saved, from its defaults
ci / fork-checks (pull_request) Successful in 20s
ci / build (pull_request) Successful in 7m26s

A singleton such as x:SpamSettings has no stored object until someone
saves it; /get shows its defaults instead. Explain looked only for the
stored object, so every setting still at its defaults answered "No
such x:SpamSettings." It now falls back to the defaults the same way.
This commit is contained in:
2026-09-26 01:09:46 -07:00
parent d9a6db025b
commit 866d7d3ed5
2 changed files with 32 additions and 4 deletions
+8 -3
View File
@@ -36,7 +36,7 @@ use registry::{
jmap::IntoValue,
schema::{
enums::SpamClassifyResult,
prelude::ObjectType,
prelude::{OBJ_SINGLETON, Object, ObjectType},
structs::{QueuedMessage, QueuedRecipient, RecipientStatus},
},
types::{EnumImpl, id::ObjectId},
@@ -431,8 +431,13 @@ a negative one toward legitimate mail. The result follows the total against the
let Ok(id) = Id::from_str(id) else {
return Ok(Err(not_found()));
};
let Some(stored) = server.registry().get(ObjectId::new(object_type, id)).await? else {
return Ok(Err(not_found()));
// A singleton never saved holds its defaults, as its /get shows it
let stored = match server.registry().get(ObjectId::new(object_type, id)).await? {
Some(stored) => stored,
None if id.is_singleton() && object_type.flags() & OBJ_SINGLETON != 0 => {
Object::from(object_type)
}
None => return Ok(Err(not_found())),
};
let stored = serde_json::to_value(stored.into_value()).unwrap_or_default();
let current = stored.get(property.as_str()).cloned().unwrap_or(serde_json::Value::Null);