You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
Implementation of the max_expiry field in ManifestCollection struct assumes it will always hold a valid u64. However, -1 may be returned when no expiration (?) is set? This results in deserialization errors when trying to cast -1 to u64.
Problem:
// Example call:
bucket.collections().get_all_scopes(GetAllScopesOptions::default()).await;// Output:DecodingFailure{ctx:{},source:Custom{kind:InvalidData,error:Error("invalid value: integer `-1`, expected u64", line:1, column:189)}}// Caused by couchbase/src/api/collections.rs:#[derive(Debug,Deserialize)]structManifestCollection{uid:String,name:String,#[serde(rename = "maxTTL")]max_expiry:u64,// <- This}
Workaroundcouchbase/src/api/collections.rs:
#[derive(Debug,Deserialize)]structManifestCollection{uid:String,name:String,#[serde(rename = "maxTTL", deserialize_with = "deserialize_max_ttl")]max_expiry:Option<u64>,// Option to represent no expiry -1 ?}// Custom deserialization function for maxTTLfndeserialize_max_ttl<'de,D>(deserializer:D) -> Result<Option<u64>,D::Error>whereD: serde::Deserializer<'de>,{let value:i64 = serde::Deserialize::deserialize(deserializer)?;if value == -1{Ok(None)// -1 represents no expiry ?}elseif value >= 0{Ok(Some(value asu64))// Valid u64 values}else{Err(serde::de::Error::custom("invalid value for max_expiry"))}}
...implCollectionManager{
...pubasyncfnget_all_scopes(&self,options:implInto<Option<GetAllScopesOptions>>,) -> CouchbaseResult<Vec<ScopeSpec>>{
...
for scope inmanifest.scopes{letmut collections = vec![];for col in scope.collections{let expiry_duration = col.max_expiry.map_or(Duration::ZERO, |secs| Duration::from_secs(secs));
collections.push(CollectionSpec::new(
col.name,
scope.name.clone(),
expiry_duration,))}
scopes.push(ScopeSpec::new(scope.name, collections));}
...
}
...}
Worked for me but not sure if something else broke 😆
The text was updated successfully, but these errors were encountered:
Description:
Implementation of the max_expiry field in ManifestCollection struct assumes it will always hold a valid u64. However, -1 may be returned when no expiration (
?
) is set? This results in deserialization errors when trying to cast -1 to u64.Problem:
Workaround
couchbase/src/api/collections.rs
:Worked for me but not sure if something else broke 😆
The text was updated successfully, but these errors were encountered: