Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Vadim-Borovikov opened this issue Oct 23, 2022 · 4 comments
Closed

Comments

@Vadim-Borovikov
Copy link

Vadim-Borovikov commented Oct 23, 2022

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
Copy link
Author

Vadim-Borovikov commented Oct 23, 2022

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
Copy link
Author

Vadim-Borovikov commented Oct 24, 2022

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 Vadim-Borovikov changed the title Body failed validation when trying erasing the property value Body failed validation when trying to update the rich text property value Oct 24, 2022
@Vadim-Borovikov Vadim-Borovikov changed the title Body failed validation when trying to update the rich text property value Body failed validation when trying to update the two properties Oct 24, 2022
@Vadim-Borovikov
Copy link
Author

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);
    }

@Vadim-Borovikov Vadim-Borovikov changed the title Body failed validation when trying to update the two properties Body failed validation when trying to update two properties at once Oct 24, 2022
@KoditkarVedant
Copy link
Contributor

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants