notion-dotnet / notion-sdk-net

A Notion SDK for .Net
MIT License
181 stars 46 forks source link

Body failed validation when trying to update two properties at once #345

Closed Vadim-Borovikov closed 12 months ago

Vadim-Borovikov commented 1 year ago

Describe the bug Pages.UpdatePropertiesAsync fails when non-empty Text property gets updated.

To Reproduce Steps to reproduce the behavior:

  1. Set up a database with Text property.
  2. Creare a page with non-empty Text property.
  3. Get this page from the database to update it.
  4. Try to set edit this property.
  5. Observe errors (see below).

Expected behavior Properties get updated, no errors from API.

Vadim-Borovikov commented 1 year ago

Trying to erase property:

When passing null, API returns error

Invalid property value for: "Text".

When passing new RichTextPropertyValue(), API returns error

body failed validation. Fix one: body.properties.Text.title should be defined, instead was undefined. body.properties.Text.rich_text should be defined, instead was undefined. body.properties.Text.number should be defined, instead was undefined. body.properties.Text.url should be defined, instead was undefined. body.properties.Text.select should be defined, instead was undefined. body.properties.Text.multi_select should be defined, instead was undefined. body.properties.Text.people should be defined, instead was undefined. body.properties.Text.email should be defined, instead was undefined. body.properties.Text.phone_number should be defined, instead was undefined. body.properties.Text.date should be defined, instead was undefined. body.properties.Text.checkbox should be defined, instead was undefined. body.properties.Text.relation should be defined, instead was undefined. body.properties.Text.files should be defined, instead was undefined. body.properties.Text.status should be defined, instead was undefined. body.properties.Text.id should be defined, instead was undefined. body.properties.Text.name should be defined, instead was undefined. body.properties.Text.start should be defined, instead was undefined.

When passing new RichTextPropertyValue { RichText = new List<RichTextBase>() }, API returns error

body failed validation. Fix one: body.properties.Text.id should be defined, instead was undefined. body.properties.Text.name should be defined, instead was undefined. body.properties.Text.start should be defined, instead was undefined.

Vadim-Borovikov commented 1 year ago

Trying to update property.

Initially, I am able to successfully fill empty Text property with code:

        RichTextPropertyValue result = new()
        {
            RichText = new List<RichTextBase>()
        };
        Text text = new() { Content = content };
        RichTextText item = new() { Text = text };
        result.RichText.Add(item);
        return result;

But If this property already have some value, I see:

body failed validation. Fix one: body.properties.MyTestField.id should be defined, instead was undefined. body.properties.MyTestField.name should be defined, instead was undefined. body.properties.MyTestField.start should be defined, instead was undefined.

Vadim-Borovikov commented 1 year ago

Okay, so my experiments show that it is something with multiple properties at nose.

This works:

    public async Task TestAsync(string pageId)
    {
        await TestUpdate(pageId, null, "https://github.com");
        await TestUpdate(pageId, "text 1", null);
        await TestUpdate(pageId, null, "https://github.com");
        await TestUpdate(pageId, "text 2", null);
        await TestUpdate(pageId, null, "https://github.com");
    }

    private async Task TestUpdate(string pageId, string? text, string? url)
    {
        Dictionary<string, PropertyValue?> properties = new()
        {
            { "Text", CreateTextValue(text) },
        };
        await _client.Pages.UpdatePropertiesAsync(pageId, properties);

        properties = new Dictionary<string, PropertyValue?>
        {
            { "URL", url is null ? null : new UrlPropertyValue { Url = url } }
        };
        await _client.Pages.UpdatePropertiesAsync(pageId, properties);
    }

and this produces errors for some reason:

    public async Task TestAsync(string pageId)
    {
        await TestUpdate(pageId, null, "https://github.com");
        await TestUpdate(pageId, "text 1", null);
        await TestUpdate(pageId, null, "https://github.com");
        await TestUpdate(pageId, "text 2", null);
        await TestUpdate(pageId, null, "https://github.com");
    }

    private async Task TestUpdate(string pageId, string? text, string? url)
    {
        Dictionary<string, PropertyValue?> properties = new()
        {
            { "Text", CreateTextValue(text) },
            { "URL", url is null ? null : new UrlPropertyValue { Url = url } }
        };
        await _client.Pages.UpdatePropertiesAsync(pageId, properties);
    }
KoditkarVedant commented 1 year ago

@Vadim-Borovikov I tried to reproduce this but it seems the problem is with the Notion API. I verified this by directly using Postman. May be you could report this at https://github.com/makenotion/notion-sdk-js