diff --git a/invokeai/app/services/workflow_records/workflow_records_common.py b/invokeai/app/services/workflow_records/workflow_records_common.py index 599d2750c2..ffc98bb786 100644 --- a/invokeai/app/services/workflow_records/workflow_records_common.py +++ b/invokeai/app/services/workflow_records/workflow_records_common.py @@ -3,10 +3,9 @@ from enum import Enum from typing import Any, Union import semver -from pydantic import BaseModel, Field, JsonValue, TypeAdapter, field_validator +from pydantic import BaseModel, ConfigDict, Field, JsonValue, TypeAdapter, field_validator from invokeai.app.util.metaenum import MetaEnum -from invokeai.app.util.misc import uuid_string __workflow_meta_version__ = semver.Version.parse("1.0.0") @@ -66,12 +65,14 @@ class WorkflowWithoutID(BaseModel): nodes: list[dict[str, JsonValue]] = Field(description="The nodes of the workflow.") edges: list[dict[str, JsonValue]] = Field(description="The edges of the workflow.") + model_config = ConfigDict(extra="forbid") + WorkflowWithoutIDValidator = TypeAdapter(WorkflowWithoutID) class Workflow(WorkflowWithoutID): - id: str = Field(default_factory=uuid_string, description="The id of the workflow.") + id: str = Field(description="The id of the workflow.") WorkflowValidator = TypeAdapter(Workflow) diff --git a/invokeai/app/services/workflow_records/workflow_records_sqlite.py b/invokeai/app/services/workflow_records/workflow_records_sqlite.py index c28a7a2d92..ecbe7c0c9b 100644 --- a/invokeai/app/services/workflow_records/workflow_records_sqlite.py +++ b/invokeai/app/services/workflow_records/workflow_records_sqlite.py @@ -14,9 +14,10 @@ from invokeai.app.services.workflow_records.workflow_records_common import ( WorkflowRecordListItemDTO, WorkflowRecordListItemDTOValidator, WorkflowRecordOrderBy, - WorkflowValidator, WorkflowWithoutID, + WorkflowWithoutIDValidator, ) +from invokeai.app.util.misc import uuid_string class SqliteWorkflowRecordsStorage(WorkflowRecordsStorageBase): @@ -66,7 +67,7 @@ class SqliteWorkflowRecordsStorage(WorkflowRecordsStorageBase): try: # Only user workflows may be created by this method assert workflow.meta.category is WorkflowCategory.User - workflow_with_id = WorkflowValidator.validate_python(workflow.model_dump()) + workflow_with_id = Workflow(**workflow.model_dump(), id=uuid_string()) self._lock.acquire() self._cursor.execute( """--sql @@ -204,7 +205,8 @@ class SqliteWorkflowRecordsStorage(WorkflowRecordsStorageBase): workflow_paths = workflows_dir.glob("*.json") for path in workflow_paths: bytes_ = path.read_bytes() - workflow = WorkflowValidator.validate_json(bytes_) + workflow_without_id = WorkflowWithoutIDValidator.validate_json(bytes_) + workflow = Workflow(**workflow_without_id.model_dump(), id=uuid_string()) workflows.append(workflow) # Only default workflows may be managed by this method assert all(w.meta.category is WorkflowCategory.Default for w in workflows)