From ff21b15861dbbc278c8205d41d4ee44d46276a20 Mon Sep 17 00:00:00 2001 From: TCeason Date: Mon, 21 Jul 2025 21:26:48 +0800 Subject: [PATCH 1/2] fix(query): Gracefully handle unknown GrantEntry objects in UserGrantSet::from_pb When an older version of the application processes `UserGrantSet` data that contains `GrantEntry` objects with newly introduced `GrantObject` types, the `GrantEntry::from_pb` conversion can fail for those specific entries. This commit modifies the `UserGrantSet::from_pb` function to gracefully handle such scenarios. If `GrantEntry::from_pb` returns an error (e.g., due to an unknown `GrantObject`), the error is now logged, and the problematic grant entry is skipped instead of causing the entire conversion to fail. This ensures that users on older versions can still log in and use their available grants, providing better forward compatibility and robustness against evolving data schemas. Without this, a user attempting to log in with data containing new `GrantObject` types would be prevented from logging in on an older client. --- Cargo.lock | 1 + src/meta/proto-conv/Cargo.toml | 1 + src/meta/proto-conv/src/user_from_to_protobuf_impl.rs | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 2af0887a305e0..6e8fb5735e302 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4096,6 +4096,7 @@ dependencies = [ "databend-common-protos", "enumflags2", "fastrace", + "log", "maplit", "num", "pretty_assertions", diff --git a/src/meta/proto-conv/Cargo.toml b/src/meta/proto-conv/Cargo.toml index 0aa5e663d00df..488ba3211daeb 100644 --- a/src/meta/proto-conv/Cargo.toml +++ b/src/meta/proto-conv/Cargo.toml @@ -16,6 +16,7 @@ databend-common-meta-types = { workspace = true } databend-common-protos = { workspace = true } enumflags2 = { workspace = true } fastrace = { workspace = true } +log = { workspace = true } num = { workspace = true } prost = { workspace = true } thiserror = { workspace = true } diff --git a/src/meta/proto-conv/src/user_from_to_protobuf_impl.rs b/src/meta/proto-conv/src/user_from_to_protobuf_impl.rs index 175b0122b9f2f..ccb21f68f3d4c 100644 --- a/src/meta/proto-conv/src/user_from_to_protobuf_impl.rs +++ b/src/meta/proto-conv/src/user_from_to_protobuf_impl.rs @@ -295,7 +295,13 @@ impl FromToProto for mt::principal::UserGrantSet { let mut entries = Vec::new(); for entry in p.entries.iter() { - entries.push(mt::principal::GrantEntry::from_pb(entry.clone())?); + // If we add new GrantObject in new version + // Rollback to old version, GrantEntry.object will be None + // GrantEntry::from_pb will return err so user can not login in old version. + match mt::principal::GrantEntry::from_pb(entry.clone()) { + Ok(entry) => entries.push(entry), + Err(e) => log::error!("GrantEntry::from_pb with error : {e}"), + } } let mut roles = HashSet::new(); for role in p.roles.iter() { From e7d4d4b2666cacfbdd4f5740389b0a1f935f6220 Mon Sep 17 00:00:00 2001 From: TCeason Date: Tue, 22 Jul 2025 15:47:00 +0800 Subject: [PATCH 2/2] make err msg more detial --- src/meta/proto-conv/src/user_from_to_protobuf_impl.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meta/proto-conv/src/user_from_to_protobuf_impl.rs b/src/meta/proto-conv/src/user_from_to_protobuf_impl.rs index ccb21f68f3d4c..5cb2cc8e6ba64 100644 --- a/src/meta/proto-conv/src/user_from_to_protobuf_impl.rs +++ b/src/meta/proto-conv/src/user_from_to_protobuf_impl.rs @@ -160,7 +160,7 @@ impl FromToProto for mt::principal::GrantObject { reader_check_msg(p.ver, p.min_reader_ver)?; let Some(object) = p.object else { - return Err(Incompatible::new("GrantObject cannot be None".to_string())); + return Err(Incompatible::new(format!("Incompatible GrantObject type: Data contains an unrecognized variant for {} version", p.ver))); }; match object {