Skip to content

Enable the Unsupported Object #419

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

Open
kosaku-hayashi opened this issue Jul 15, 2024 · 1 comment
Open

Enable the Unsupported Object #419

kosaku-hayashi opened this issue Jul 15, 2024 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@kosaku-hayashi
Copy link
Contributor

Description

Currently, if a property or block newly added to Notion is included in the response, a serializer exception is raised and the
The client will stop working.

Example:
Newtonsoft.Json.JsonSerializationException: 'Error converting value "{New property or block}" to type 'Notion.Client.PropertyValueType'

This is because there is no matching enum value for the type string, and the existing StringEnumConverter does not support returning a default value in such cases.
The existing code provides a class that accepts unsupported blocks called UnsupportedBlock, but this is effectively a non-functional state.

// Some other attributes
[JsonSubtypes.KnownSubTypeAttribute(typeof(UnsupportedBlock), BlockType.Unsupported)] <-- It will never be deserialized.
public interface IBlock : IObject, IObjectModificationData
{
    [JsonProperty("type")]
    [JsonConverter(typeof(StringEnumConverter))] <-- Cannot return default value if enum value does not exist
    BlockType Type { get; set; }

    [JsonProperty("has_children")]
    bool HasChildren { get; set; }

    [JsonProperty("in_trash")]
    bool InTrash { get; set; }

    [JsonProperty("parent")]
    IBlockParent Parent { get; set; }
}
public enum BlockType
{
    // Some other Type values

    [EnumMember(Value = "unsupported")] <-- Newly added block type values are never "unsupported".
    Unsupported
}

This problem could be remedied by creating a custom converter that returns a default value (i.e., "UnSupported") if the type string does not match and defining it on the enum side.
Property and PropertyValue also raise the same exception, so it may be necessary to create UnSupportedProperty and UnSupportedPropertyValue in a similar manner.

@KoditkarVedant KoditkarVedant added this to the 4.3.0 milestone Oct 29, 2024
@KoditkarVedant KoditkarVedant added the enhancement New feature or request label Oct 29, 2024
@KoditkarVedant
Copy link
Contributor

@kosaku-hayashi Unsupported is a valid return type from Notion as mentioned here.

I see another way support this by converting the BlockType to string and using the JsonSubtypes.FallBackSubType and JsonExtensionData. I will give it a try. There are other places this could help.

Until that is done, I would try my best to keep the library update to date with changes, and feel free to submit the PRs if you find something is missing.

I'm pushing this to next milestone.

@KoditkarVedant KoditkarVedant modified the milestones: 4.3.0, 4.4.0 Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants