Repository navigation
fix(database): parse new schema property types and skip unknown ones - #114
Merged
Merged
Conversation
Notion returns verification, unique_id and button entries in database and data source schemas. Without a property object for them, hydrating any database or data source that holds one threw, which failed whole search and retrieve results.
…bject A schema property type the SDK does not model yet now hydrates as an UnsupportedPropertyObject that keeps its id, name, type and raw data, like UnsupportedBlock does for blocks. One new Notion property type no longer breaks parsing of a whole database, data source or search result. UnsupportedPropertyObjectException stays available for backward compatibility but is no longer thrown.
1 of 7 tasks
…pdates Notion's property reference describes Button and Verification schemas as response-only, and the API cannot create a Verification property through a schema write. Treat both like the other computed configurations so a retrieved data source can be sent back unchanged.
An UnsupportedPropertyObject holds no writable configuration, so sending it back produced an entry with only id, name and type. Notion keeps existing properties that an update omits, so leaving it out is the only write that cannot change or reject the schema, matching how UnsupportedBlock writes no block content.
Database::toArrayForUpdate() still sends the property schema on Notion versions before 2025-09-03, which is the SDK default, but it never filtered computed or unsupported configurations the way data sources do. Move the read-only types onto the property objects as isWritable(), with UnsupportedPropertyObject never writable, and use it for both data source and database updates.
This reverts commit d6bc397. The public isWritable() it added reported writable created and edited columns as read-only, and returned true on a freshly built property object whose type is not set yet. Its Database filter also turned typed created_time and last_edited_time writes on Notion versions before 2025-09-03 into silent no-ops. Data source updates keep their private read-only list and the UnsupportedPropertyObject omission.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds schema property objects for the three types Notion returns in database and data source schemas that the SDK could not parse:
VerificationPropertyObjectwith an emptyVerificationPropertyConfiguration;UniqueIdPropertyObjectwith aUniqueIdPropertyConfigurationexposinggetPrefix()/setPrefix();ButtonPropertyObjectwith an emptyButtonPropertyConfiguration.They follow the existing
PlacePropertyObjectandPhoneNumberPropertyObjectshape.AbstractPropertyObject::getMapClassFromType()now falls back to a newUnsupportedPropertyObjectfor any type without a property object class, the same wayAbstractBlockfalls back toUnsupportedBlock. The fallback keeps the property'sid,nameandtype, andgetRawData()returns the untouched configuration.DataSource::toArrayForUpdate()leaves out two more kinds of property.buttonandverificationjoin the computed types (created_by,created_time,last_edited_by,last_edited_time) in its private read-only list, and everyUnsupportedPropertyObjectis skipped.Databaseupdate payloads are unchanged.UnsupportedPropertyObjectExceptionis kept for backward compatibility. Nothing throws it any more, so the stale@throwstags onAbstractPropertyObject,DataSourceandDatabaseare removed.Motivation and context
getMapClassFromType()threwUnsupportedPropertyObjectExceptionfor every schema type without a matching class. Every wiki database has averificationproperty, andunique_idandbuttonare common, soDataSource::fromRawData()andDatabase::fromRawData()threw on those schemas. The exception failed the wholesearch,dataSources()->retrieve()ordatabases()->retrieve()result, not just the one property.Page property values already handle all three types (
VerificationPropertyValue,UniqueIdPropertyValue,ButtonPropertyValue); only the schema side was missing.Once those schemas parse, a retrieved data source can be sent back through
dataSources()->update(). The Property object reference says "Button and Verification schemas are response-only", so both join the computed types that data source updates already omit. An unsupported property has no configuration the SDK can vouch for, so it is omitted too. The Update data source properties reference says "Existing properties that you omit stay unchanged".UnsupportedBlockwrites no block content back either. One trade-off: a raw array with a mistyped type passed toDataSource::setProperties()is now left out of the update instead of being rejected.Schema shapes, checked against:
"verification": {}("Its schema response has an emptyverificationobject"),"unique_id": { "prefix": "TASK" }("Itsprefixis a string ornull"),"button": {}("A Button property has an emptybuttonobject in schema responses");src/api-endpoints/data-sources.ts(UniqueIdDatabasePropertyConfigResponse:unique_id: { prefix: string | null }) andsrc/api-endpoints/common.ts(VerificationPropertyConfigurationRequest:verification: EmptyObject,ButtonPropertyConfigurationRequest:button: EmptyObject,UniqueIdPropertyConfigurationRequest:unique_id: { prefix?: string | null }), at makenotion/notion-sdk-js@10aa976.How has this been tested?
Local commands ran on PHP 8.3 (
php:8.3-cli) at 96bb27d, the last commit beforemain(with #115) was merged in. The merge only touchescomposer.json, andvendor/bin/phpunit --no-coveragegives the same result at the merge head, 1b43231.vendor/bin/phpunit --no-coverage: 310 tests, 2613 assertions, all passing.DataSourceTest::testDataSourceHydratesVerificationUniqueIdAndButtonPropertyConfigurationshydrates a data source whose schema holdsverification,unique_id(prefixTASK) andbutton. It checks that each one maps to its class, reads the prefix, and thattoArray()returns each property with the same keys and values Notion sent. Before the change it fails withUnsupportedPropertyObjectException: The given property object "verification" is unsupported.DataSourceTest::testDataSourceHydratesUnknownPropertyTypeAsUnsupportedPropertyObjecthydrates a schema with an unknownfuture_typeproperty. It checks the fallback class, itsid,name,typeand raw data, that the other properties still hydrate, and thattoArrayForUpdate()leaves it out. Before the change it fails with the same exception.DataSourceTest::testUpdateSerializationOmitsReadOnlyPropertyConfigurationsnow also coversverificationandbutton. It failed withFailed asserting that an array does not have the key 'Verification'before they were treated as read-only.DataSourceTest::testSetPropertiesRejectsRawArrayWithUnknownTypeasserted the old exception. It is nowtestSetPropertiesFallsBackToUnsupportedPropertyObjectForUnknownTypeand asserts the fallback.vendor/bin/phpstan analyse,vendor/bin/psalm --no-cache,vendor/bin/phpcsandvendor/bin/parallel-lint src testsreport no errors.php -lon every changed file under PHP 7.4 reports no syntax errors.Types of changes
PR checklist