diff --git a/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs index 74c94c82..63d333d9 100644 --- a/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs @@ -9,7 +9,7 @@ public class SelectPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Select; - [JsonProperty("select")] + [JsonProperty("select", NullValueHandling = NullValueHandling.Include)] public SelectOption Select { get; set; } } } diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index a0f51d71..f0833be5 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -247,4 +247,98 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } + + [Fact] + public async Task Bug_exception_when_attempting_to_set_select_property_to_nothing() + { + // Arrange + var databaseCreateRequest = new DatabasesCreateParameters + { + Title = + new List + { + new RichTextTextInput() { Text = new Text { Content = "Test Database" } } + }, + Parent = new ParentPageInput() { PageId = ParentPageId }, + Properties = new Dictionary + { + { + "title", new TitlePropertySchema + { + Title = new Dictionary() + } + }, + { + "Colors1", + new SelectPropertySchema + { + Select = new OptionWrapper + { + Options = new List + { + new() { Name = "Red" }, + new() { Name = "Green" }, + new() { Name = "Blue" } + } + } + } + }, + { + "Colors2", + new SelectPropertySchema + { + Select = new OptionWrapper + { + Options = new List + { + new() { Name = "Red" }, + new() { Name = "Green" }, + new() { Name = "Blue" } + } + } + } + }, + } + }; + + var database = await Client.Databases.CreateAsync(databaseCreateRequest); + + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput { DatabaseId = database.Id }) + .AddProperty("title", + new TitlePropertyValue + { + Title = new List + { + new RichTextTextInput { Text = new Text { Content = "Test" } } + } + }) + .AddProperty("Colors1", new SelectPropertyValue { Select = new SelectOption { Name = "Red" } }) + .AddProperty("Colors2", new SelectPropertyValue { Select = new SelectOption { Name = "Green" } }) + .Build(); + + // Act + var page = await Client.Pages.CreateAsync(pagesCreateParameters); + + var updatePageRequest = new PagesUpdateParameters + { + Properties = new Dictionary + { + { "Colors1", new SelectPropertyValue { Select = new SelectOption { Name = "Blue" } } }, + { "Colors2", new SelectPropertyValue { Select = null } } + } + }; + + var updatedPage = await Client.Pages.UpdateAsync(page.Id, updatePageRequest); + + // Assert + page.Properties["Colors1"].As().Select.Name.Should().Be("Red"); + page.Properties["Colors2"].As().Select.Name.Should().Be("Green"); + + updatedPage.Properties["Colors1"].As().Select.Name.Should().Be("Blue"); + updatedPage.Properties["Colors2"].As().Select.Should().BeNull(); + + await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Databases.UpdateAsync(database.Id, new DatabasesUpdateParameters { Archived = true }); + } }