Skip to content

Commit

Permalink
Merge pull request #532 from fractal-analytics-platform/pydantic_v2
Browse files Browse the repository at this point in the history
Supported pydantic_v2 schemas
  • Loading branch information
zonia3000 authored Jul 22, 2024
2 parents 1b6285d + 9e15b70 commit 34cffcd
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
*Note: Numbers like (\#123) point to closed Pull Requests on the fractal-web repository.*

# Unreleased

* Supported `pydantic_v2` schemas (\#532);

# 1.3.1

* Fixed custom key not displayed in JSON Schema form (\#529);
Expand Down
5 changes: 4 additions & 1 deletion sandbox/src/lib/components/TaskManifestSandbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@
throw new Error('Invalid manifest format');
} else if (manifestData.manifest_version !== '2') {
throw new Error('Unsupported manifest version');
} else if (manifestData.args_schema_version !== 'pydantic_v1') {
} else if (
manifestData.args_schema_version !== 'pydantic_v2' &&
manifestData.args_schema_version !== 'pydantic_v1'
) {
throw new Error('Unsupported manifest args schema version');
} else {
return manifestData;
Expand Down
2 changes: 1 addition & 1 deletion sandbox/src/lib/components/manifest_v2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "ManifestV2",
"description": "Packages containing tasks are required to include a special file\n`__FRACTAL_MANIFEST__.json` in order to be discovered and used by Fractal.\n\nThis model class and the model classes it depends on provide the base\nschema to read, write and validate manifests.\n\nAttributes:\n manifest_version:\n A version string that provides indication for compatibility between\n manifests as the schema evolves. This is for instance used by\n Fractal to determine which subclass of the present base class needs\n be used to read and validate the input.\n task_list : list[TaskManifestType]\n The list of tasks, represented as specified by subclasses of the\n _TaskManifestBase (a.k.a. TaskManifestType)\n has_args_schemas:\n `True` if the manifest incldues JSON Schemas for the arguments of\n each task.\n args_schema_version:\n Label of how `args_schema`s were generated (e.g. `pydantic_v1`).",
"description": "Packages containing tasks are required to include a special file\n`__FRACTAL_MANIFEST__.json` in order to be discovered and used by Fractal.\n\nThis model class and the model classes it depends on provide the base\nschema to read, write and validate manifests.\n\nAttributes:\n manifest_version:\n A version string that provides indication for compatibility between\n manifests as the schema evolves. This is for instance used by\n Fractal to determine which subclass of the present base class needs\n be used to read and validate the input.\n task_list : list[TaskManifestType]\n The list of tasks, represented as specified by subclasses of the\n _TaskManifestBase (a.k.a. TaskManifestType)\n has_args_schemas:\n `True` if the manifest incldues JSON Schemas for the arguments of\n each task.\n args_schema_version:\n Label of how `args_schema`s were generated (e.g. `pydantic_v2`).",
"type": "object",
"properties": {
"manifest_version": {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/v1/workflow/ArgumentsSchema.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { deepCopy } from '$lib/common/component_utilities';
import { JsonSchemaDataError } from 'fractal-jschema/components/form_manager';
const SUPPORTED_SCHEMA_VERSIONS = ['pydantic_v1'];
const SUPPORTED_SCHEMA_VERSIONS = ['pydantic_v1', 'pydantic_v2'];
/** @type {import('$lib/components/common/StandardErrorAlert.svelte').default|undefined} */
let errorAlert = undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/v2/tasks/AddSingleTask.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
let version = '';
let docs_info = '';
let docs_link = '';
let args_schema_version = 'pydantic_v1';
let args_schema_version = 'pydantic_v2';
/** @type {import('$lib/types-v2').TaskV2Type} */
let taskType = 'non_parallel';
Expand Down Expand Up @@ -314,7 +314,7 @@
typesEditor.init({}, {});
docs_info = '';
docs_link = '';
args_schema_version = 'pydantic_v1';
args_schema_version = 'pydantic_v2';
clearArgsSchemaNonParallelFileUpload();
clearArgsSchemaParallelFileUpload();
clearMetaNonParallelFileUpload();
Expand Down
5 changes: 4 additions & 1 deletion src/lib/components/v2/tasks/CustomEnvTask.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
throw new Error('Invalid manifest format');
} else if (manifestData.manifest_version !== '2') {
throw new Error('Unsupported manifest version');
} else if (manifestData.args_schema_version !== 'pydantic_v1') {
} else if (
manifestData.args_schema_version !== 'pydantic_v2' &&
manifestData.args_schema_version !== 'pydantic_v1'
) {
throw new Error('Unsupported manifest args schema version');
} else {
return manifestData;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/v2/tasks/manifest_v2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "ManifestV2",
"description": "Packages containing tasks are required to include a special file\n`__FRACTAL_MANIFEST__.json` in order to be discovered and used by Fractal.\n\nThis model class and the model classes it depends on provide the base\nschema to read, write and validate manifests.\n\nAttributes:\n manifest_version:\n A version string that provides indication for compatibility between\n manifests as the schema evolves. This is for instance used by\n Fractal to determine which subclass of the present base class needs\n be used to read and validate the input.\n task_list : list[TaskManifestType]\n The list of tasks, represented as specified by subclasses of the\n _TaskManifestBase (a.k.a. TaskManifestType)\n has_args_schemas:\n `True` if the manifest incldues JSON Schemas for the arguments of\n each task.\n args_schema_version:\n Label of how `args_schema`s were generated (e.g. `pydantic_v1`).",
"description": "Packages containing tasks are required to include a special file\n`__FRACTAL_MANIFEST__.json` in order to be discovered and used by Fractal.\n\nThis model class and the model classes it depends on provide the base\nschema to read, write and validate manifests.\n\nAttributes:\n manifest_version:\n A version string that provides indication for compatibility between\n manifests as the schema evolves. This is for instance used by\n Fractal to determine which subclass of the present base class needs\n be used to read and validate the input.\n task_list : list[TaskManifestType]\n The list of tasks, represented as specified by subclasses of the\n _TaskManifestBase (a.k.a. TaskManifestType)\n has_args_schemas:\n `True` if the manifest incldues JSON Schemas for the arguments of\n each task.\n args_schema_version:\n Label of how `args_schema`s were generated (e.g. `pydantic_v2`).",
"type": "object",
"properties": {
"manifest_version": {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/v2/workflow/ArgumentsSchema.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { tick } from 'svelte';
import { JsonSchemaDataError } from 'fractal-jschema/components/form_manager';
const SUPPORTED_SCHEMA_VERSIONS = ['pydantic_v1'];
const SUPPORTED_SCHEMA_VERSIONS = ['pydantic_v1', 'pydantic_v2'];
/** @type {import('$lib/components/common/StandardErrorAlert.svelte').default|undefined} */
let errorAlert = undefined;
Expand Down
6 changes: 3 additions & 3 deletions tests/v2/add_single_task.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('Add single tasks [v2]', async ({ page }) => {
expect(task.source).toEqual(`admin:${randomTaskName1}-source`);
expect(task.input_types).toContain('input_type');
expect(task.output_types).toContain('output_type');
expect(task.args_schema_version).toEqual('pydantic_v1');
expect(task.args_schema_version).toEqual('pydantic_v2');
expect(task.docs_info).toEqual('Task title');
expect(task.docs_link).toEqual('https://www.example.com');
});
Expand Down Expand Up @@ -81,7 +81,7 @@ test('Add single tasks [v2]', async ({ page }) => {
expect(task.source).toEqual(`admin:${randomTaskName2}-source`);
expect(task.input_types).toContain('input_type');
expect(task.output_types).toContain('output_type');
expect(task.args_schema_version).toEqual('pydantic_v1');
expect(task.args_schema_version).toEqual('pydantic_v2');
expect(task.docs_info).toEqual('Task title');
expect(task.docs_link).toEqual('https://www.example.com');
});
Expand Down Expand Up @@ -118,7 +118,7 @@ test('Add single tasks [v2]', async ({ page }) => {
expect(task.source).toEqual(`admin:${randomTaskName3}-source`);
expect(task.input_types).toContain('input_type');
expect(task.output_types).toContain('output_type');
expect(task.args_schema_version).toEqual('pydantic_v1');
expect(task.args_schema_version).toEqual('pydantic_v2');
expect(task.docs_info).toEqual('Task title');
expect(task.docs_link).toEqual('https://www.example.com');
});
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/custom_env_task.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('Custom Python env task [v2]', async ({ page }) => {
const randomName = Math.random().toString(36).substring(7);

const manifestData = {
args_schema_version: 'pydantic_v1',
args_schema_version: 'pydantic_v2',
has_args_schemas: true,
manifest_version: '2',
task_list: [
Expand Down

0 comments on commit 34cffcd

Please sign in to comment.