From a069b1837ca3fb70c4c20488e6506fb097b3a3cb Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 23 Jan 2024 10:18:25 -0500 Subject: [PATCH 1/7] Boost dandischema to 0.9.* series so we get support for pydantic 2.0 and schema 0.6.5 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 71cb5b6ad..1f10b04df 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ include_package_data=True, install_requires=[ 'celery', - 'dandischema~=0.8.4', + 'dandischema~=0.9.0', 'django~=4.1.0', 'django-admin-display', # Require 0.58.0 as it is the first version to support postgres' native From abfaec7c52c48e9a8ebacda0981a06c96b95a75c Mon Sep 17 00:00:00 2001 From: Isaac To Date: Wed, 24 Jan 2024 23:00:19 -0800 Subject: [PATCH 2/7] Adjust to new error msg in `test_validate_version_metadata_no_assets` The validator for the `assetsSummary` field in the `PublishedDandiset` model in dandischema 0.9.0 generates an error with a slightly different message --- dandiapi/api/tests/test_tasks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dandiapi/api/tests/test_tasks.py b/dandiapi/api/tests/test_tasks.py index 80ea1d39e..d421835c5 100644 --- a/dandiapi/api/tests/test_tasks.py +++ b/dandiapi/api/tests/test_tasks.py @@ -292,7 +292,8 @@ def test_validate_version_metadata_no_assets( assert draft_version.validation_errors == [ { 'field': 'assetsSummary', - 'message': 'A Dandiset containing no files or zero bytes is not publishable', + 'message': 'Value error, ' + 'A Dandiset containing no files or zero bytes is not publishable', } ] From 117d73de21281224d96e791a3e3778e44b4d2743 Mon Sep 17 00:00:00 2001 From: Isaac To Date: Wed, 24 Jan 2024 23:13:57 -0800 Subject: [PATCH 3/7] Adjust to new error msg in `test_validate_asset_metadata_no_digest` The validator for the `digest` field in the `PublishedAsset` model in dandischema 0.9.0 generates an error with a slightly different message than before --- dandiapi/api/tests/test_tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dandiapi/api/tests/test_tasks.py b/dandiapi/api/tests/test_tasks.py index d421835c5..ee9a00da6 100644 --- a/dandiapi/api/tests/test_tasks.py +++ b/dandiapi/api/tests/test_tasks.py @@ -153,7 +153,7 @@ def test_validate_asset_metadata_no_digest(draft_asset: Asset): assert draft_asset.status == Asset.Status.INVALID assert draft_asset.validation_errors == [ - {'field': 'digest', 'message': 'A non-zarr asset must have a sha2_256.'} + {'field': 'digest', 'message': 'Value error, A non-zarr asset must have a sha2_256.'} ] From 881d03f8f67c7f4b296509259d0a39bd7ffc4832 Mon Sep 17 00:00:00 2001 From: Isaac To Date: Fri, 26 Jan 2024 15:58:03 -0800 Subject: [PATCH 4/7] Replace use of deprecated methods from `Dandiset` in `dandi-schema` package --- dandiapi/api/services/version/metadata.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dandiapi/api/services/version/metadata.py b/dandiapi/api/services/version/metadata.py index ed3f10011..125b5c5f2 100644 --- a/dandiapi/api/services/version/metadata.py +++ b/dandiapi/api/services/version/metadata.py @@ -43,4 +43,6 @@ def _normalize_version_metadata( } # Run the version_metadata through the pydantic model to automatically include any boilerplate # like the access or repository fields - return PydanticDandiset.unvalidated(**version_metadata).json_dict() + return PydanticDandiset.model_construct( + **version_metadata + ).model_dump(mode='json',exclude_none=True) From 172c2c52c9c448cf02d51e39710e9546485e4eb7 Mon Sep 17 00:00:00 2001 From: Isaac To Date: Fri, 26 Jan 2024 16:56:22 -0800 Subject: [PATCH 5/7] Format with `ruff` --- dandiapi/api/services/version/metadata.py | 6 +++--- dandiapi/api/tests/test_tasks.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dandiapi/api/services/version/metadata.py b/dandiapi/api/services/version/metadata.py index 125b5c5f2..bc04c8114 100644 --- a/dandiapi/api/services/version/metadata.py +++ b/dandiapi/api/services/version/metadata.py @@ -43,6 +43,6 @@ def _normalize_version_metadata( } # Run the version_metadata through the pydantic model to automatically include any boilerplate # like the access or repository fields - return PydanticDandiset.model_construct( - **version_metadata - ).model_dump(mode='json',exclude_none=True) + return PydanticDandiset.model_construct(**version_metadata).model_dump( + mode='json', exclude_none=True + ) diff --git a/dandiapi/api/tests/test_tasks.py b/dandiapi/api/tests/test_tasks.py index ee9a00da6..bfffb13f0 100644 --- a/dandiapi/api/tests/test_tasks.py +++ b/dandiapi/api/tests/test_tasks.py @@ -293,7 +293,7 @@ def test_validate_version_metadata_no_assets( { 'field': 'assetsSummary', 'message': 'Value error, ' - 'A Dandiset containing no files or zero bytes is not publishable', + 'A Dandiset containing no files or zero bytes is not publishable', } ] From b22308e3ceb0ec9087f2572199b4280713eb4d0c Mon Sep 17 00:00:00 2001 From: Mike VanDenburgh Date: Fri, 9 Feb 2024 17:16:49 -0500 Subject: [PATCH 6/7] Update `definitions` to `$defs` This seems to be a breaking change in pydantics json schema export function. --- web/src/views/CreateDandisetView/CreateDandisetView.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/views/CreateDandisetView/CreateDandisetView.vue b/web/src/views/CreateDandisetView/CreateDandisetView.vue index e6c834683..7fb952f2a 100644 --- a/web/src/views/CreateDandisetView/CreateDandisetView.vue +++ b/web/src/views/CreateDandisetView/CreateDandisetView.vue @@ -181,7 +181,7 @@ const descriptionMaxLength: ComputedRef = computed( () => store.schema.properties.description.maxLength, ); const dandiLicenses: ComputedRef = computed( - () => store.schema.definitions.LicenseType.enum, + () => store.schema.$defs.LicenseType.enum, ); if (!loggedIn()) { From dd2c7b32ddea5984ee2b876f6b8aba8e6ce2e010 Mon Sep 17 00:00:00 2001 From: Mike VanDenburgh Date: Fri, 9 Feb 2024 17:26:48 -0500 Subject: [PATCH 7/7] Fix "Schema Key" becoming an entry in the meditor Pydantic 2.0's JSON schema export no longer specifies a `type` field for the `schemaKey` property, and leaves it undefined instead. This change makes it so an undefined type also delegates it as a "basic schema", meaning it will not be rendered as its own tab in the meditor. --- web/src/components/Meditor/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/Meditor/types.ts b/web/src/components/Meditor/types.ts index c6b0a7fae..5ca93b13f 100644 --- a/web/src/components/Meditor/types.ts +++ b/web/src/components/Meditor/types.ts @@ -65,7 +65,7 @@ export const isJSONSchema = (schema: JSONSchemaUnionType): schema is JSONSchema7 export const isBasicSchema = (schema: JSONSchemaUnionType): schema is BasicSchema => ( isJSONSchema(schema) - && isBasicType(schema.type) + && (isBasicType(schema.type) || schema.type === undefined) ); export const isObjectSchema = (schema: JSONSchemaUnionType): schema is ObjectSchema => (