diff --git a/invokeai/app/services/shared/sqlite_migrator/migrations/migration_22.py b/invokeai/app/services/shared/sqlite_migrator/migrations/migration_22.py index 1d9c81529e..2cd2101341 100644 --- a/invokeai/app/services/shared/sqlite_migrator/migrations/migration_22.py +++ b/invokeai/app/services/shared/sqlite_migrator/migrations/migration_22.py @@ -2,7 +2,7 @@ import json import sqlite3 from logging import Logger from pathlib import Path -from typing import NamedTuple +from typing import Any, NamedTuple from pydantic import ValidationError @@ -29,8 +29,9 @@ class Migration22Callback: for model_id, config_json in rows: try: + migrated_config_dict = self._migrate_config(config_json) # Get the model config as a pydantic object - config = AnyModelConfigValidator.validate_json(config_json) + config = AnyModelConfigValidator.validate_python(migrated_config_dict) except ValidationError: # This could happen if the config schema changed in a way that makes old configs invalid. Unlikely # for users, more likely for devs testing out migration paths. @@ -76,6 +77,26 @@ class Migration22Callback: self._prune_empty_directories() + def _migrate_config(self, config_json: Any) -> str | None: + config_dict = json.loads(config_json) + + # TODO: migrate fields, review changes to ensure we hit all cases for v6.7.0 to v6.8.0 upgrade. + + # Prior to v6.8.0, we used an awkward combination of `config_path` and `variant` to distinguish between FLUX + # variants. + # + # `config_path` was set to one of: + # - flux-dev + # - flux-dev-fill + # - flux-schnell + # + # `variant` was set to ModelVariantType.Inpaint for FLUX Fill models and ModelVariantType.Normal for all other FLUX + # models. + # + # We now use the `variant` field to directly represent the FLUX variant type, and `config_path` is no longer used. + + return config_dict + def _normalize_model_storage(self, key: str, path_value: str) -> NormalizeResult: models_dir = self._models_dir stored_path = Path(path_value) diff --git a/invokeai/backend/model_manager/configs/main.py b/invokeai/backend/model_manager/configs/main.py index 890a4f8462..26f6b5b60e 100644 --- a/invokeai/backend/model_manager/configs/main.py +++ b/invokeai/backend/model_manager/configs/main.py @@ -264,18 +264,6 @@ class Main_Checkpoint_FLUX_Config(Checkpoint_Config_Base, Main_Config_Base, Conf base: Literal[BaseModelType.Flux] = Field(default=BaseModelType.Flux) variant: FluxVariantType = Field() - # Prior to v6.8.0, we used an awkward combination of `config_path` and `variant` to distinguish between FLUX - # variants. - # - # `config_path` was set to one of: - # - flux-dev - # - flux-dev-fill - # - flux-schnell - # - # `variant` was set to ModelVariantType.Inpaint for FLUX Fill models and ModelVariantType.Normal for all other FLUX - # models. - # - # We now use the `variant` field to directly represent the FLUX variant type, and `config_path` is no longer used. @classmethod def from_model_on_disk(cls, mod: ModelOnDisk, override_fields: dict[str, Any]) -> Self: