Skip to content

Commit

Permalink
fix bug with missing UniqueID.number field in PageProperty.
Browse files Browse the repository at this point in the history
I ran into a bug today where my notion-client was failing to deserialize a Page containing a PageProperty.UniqueID.unique_id field
whose UniqueIDPropertyValue.number field was null. 99.999% of the time UniqueIDPropertyValue.number is non-null, but it can be null
for instance in the case where you use one of Notion's templates to create a Task Page with a null UniqueIDPropertyValue.number
field, but that's OK because the Task Page will always be copied to make a new Task and the unique ID field will be filled in with
some value.

This change to make number an Option<Number> instead of just Number reflects the fact that it could be null, though it is very
unlikely.
  • Loading branch information
Melvillian committed Oct 3, 2024
1 parent 7faebf3 commit ace91ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/endpoints/search/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,12 @@ fn test_search_by_title_200() {
));
assert!(result.is_ok())
}

#[test]
fn test_search_by_title_failure() {
let result = serde_json::from_str::<SearchByTitleResponse>(include_str!(

Check failure on line 38 in src/endpoints/search/tests.rs

View workflow job for this annotation

GitHub Actions / build

couldn't read `src/endpoints/search/tests/search_by_title_failure_with_missing_unique_id.json`: No such file or directory (os error 2)
"tests/search_by_title_failure_with_missing_unique_id.json"
));
dbg!(&result);
assert!(result.is_ok())
}
4 changes: 3 additions & 1 deletion src/objects/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ pub struct SelectPropertyValue {

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct UniqueIDPropertyValue {
pub number: Number,
#[serde(default)]
#[doc = "This field is null only in extremely rare cases, for instance when it's being used as a Template for a Task in Notion's Project Management Template: https://www.notion.so/templates/notion-projects-and-tasks"]
pub number: Option<Number>,
pub prefix: Option<String>,
}

Expand Down

0 comments on commit ace91ac

Please sign in to comment.