From 9a2061f738b5f8b5b2a7a3794a8b87d59d2f1c56 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Thu, 5 Dec 2024 17:25:05 +0000 Subject: [PATCH] Hack to work around `serde(untagged)` not working with u128 values (#6994) --- backend/canisters/community/impl/src/lib.rs | 9 +++++++-- .../src/communities/delete_channel_tests.rs | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/backend/canisters/community/impl/src/lib.rs b/backend/canisters/community/impl/src/lib.rs index 56ff187857..6191904f57 100644 --- a/backend/canisters/community/impl/src/lib.rs +++ b/backend/canisters/community/impl/src/lib.rs @@ -332,9 +332,9 @@ struct Data { description: Timestamped, #[serde(deserialize_with = "deserialize_maybe_timestamped")] rules: Timestamped, - #[serde(deserialize_with = "deserialize_maybe_timestamped")] + #[serde(deserialize_with = "deserialize_optional_document")] avatar: Timestamped>, - #[serde(deserialize_with = "deserialize_maybe_timestamped")] + #[serde(deserialize_with = "deserialize_optional_document")] banner: Timestamped>, #[serde(deserialize_with = "deserialize_maybe_timestamped")] permissions: Timestamped, @@ -965,3 +965,8 @@ pub struct AddUsersToChannelResult { pub users_already_in_channel: Vec, pub users_limit_reached: Vec, } + +fn deserialize_optional_document<'de, D: Deserializer<'de>>(d: D) -> Result>, D::Error> { + let document = Option::deserialize(d)?; + Ok(Timestamped::new(document, now_millis())) +} diff --git a/backend/integration_tests/src/communities/delete_channel_tests.rs b/backend/integration_tests/src/communities/delete_channel_tests.rs index 1393f7dc5f..ceed82ff09 100644 --- a/backend/integration_tests/src/communities/delete_channel_tests.rs +++ b/backend/integration_tests/src/communities/delete_channel_tests.rs @@ -94,7 +94,7 @@ fn stable_memory_garbage_collected_after_deleting_channel() { assert_eq!( get_stable_memory_map(env, community_id, STABLE_MEMORY_MAP_MEMORY_ID).len(), - 87 + 88 ); client::community::happy_path::delete_channel(env, user1.principal, community_id, channel_id2); @@ -102,7 +102,7 @@ fn stable_memory_garbage_collected_after_deleting_channel() { env.advance_time(Duration::from_secs(60)); env.tick(); - assert_eq!(get_stable_memory_map(env, community_id, STABLE_MEMORY_MAP_MEMORY_ID).len(), 3); + assert_eq!(get_stable_memory_map(env, community_id, STABLE_MEMORY_MAP_MEMORY_ID).len(), 4); } fn init_test_data(env: &mut PocketIc, canister_ids: &CanisterIds, controller: Principal) -> TestData {