mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(config): edge cases in models.yaml migration
When running the configurator, the `legacy_models_conf_path` was stripped when saving the config file. Then the migration logic didn't fire correctly, and the custom models.yaml paths weren't migrated into the db. - Rework the logic to migrate this path by adding it to the config object as a normal field that is not excluded from serialization. - Rearrange the models.yaml migration logic to remove the legacy path after migrating, then write the config file. This way, the legacy path doesn't stick around. - Move the schema version into the config object. - Back up the config file before attempting migration. - Add tests to cover this edge case
This commit is contained in:
@ -9,16 +9,14 @@ from pydantic import ValidationError
|
||||
from invokeai.app.services.config.config_default import InvokeAIAppConfig, get_config, load_and_migrate_config
|
||||
|
||||
v4_config = """
|
||||
meta:
|
||||
schema_version: 4
|
||||
schema_version: 4
|
||||
|
||||
host: "192.168.1.1"
|
||||
port: 8080
|
||||
"""
|
||||
|
||||
invalid_v5_config = """
|
||||
meta:
|
||||
schema_version: 5
|
||||
schema_version: 5
|
||||
|
||||
host: "192.168.1.1"
|
||||
port: 8080
|
||||
@ -44,6 +42,12 @@ InvokeAI:
|
||||
max_vram_cache_size: 50
|
||||
"""
|
||||
|
||||
v3_config_with_bad_values = """
|
||||
InvokeAI:
|
||||
Web Server:
|
||||
port: "ice cream"
|
||||
"""
|
||||
|
||||
invalid_config = """
|
||||
i like turtles
|
||||
"""
|
||||
@ -88,6 +92,29 @@ def test_migrate_v3_config_from_file(tmp_path: Path):
|
||||
assert not hasattr(config, "esrgan")
|
||||
|
||||
|
||||
def test_migrate_v3_backup(tmp_path: Path):
|
||||
"""Test the backup of the config file."""
|
||||
temp_config_file = tmp_path / "temp_invokeai.yaml"
|
||||
temp_config_file.write_text(v3_config)
|
||||
|
||||
load_and_migrate_config(temp_config_file)
|
||||
assert temp_config_file.with_suffix(".yaml.bak").exists()
|
||||
assert temp_config_file.with_suffix(".yaml.bak").read_text() == v3_config
|
||||
|
||||
|
||||
def test_failed_migrate_backup(tmp_path: Path):
|
||||
"""Test the failed migration of the config file."""
|
||||
temp_config_file = tmp_path / "temp_invokeai.yaml"
|
||||
temp_config_file.write_text(v3_config_with_bad_values)
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
load_and_migrate_config(temp_config_file)
|
||||
assert temp_config_file.with_suffix(".yaml.bak").exists()
|
||||
assert temp_config_file.with_suffix(".yaml.bak").read_text() == v3_config_with_bad_values
|
||||
assert temp_config_file.exists()
|
||||
assert temp_config_file.read_text() == v3_config_with_bad_values
|
||||
|
||||
|
||||
def test_bails_on_invalid_config(tmp_path: Path):
|
||||
"""Test reading configuration from a file."""
|
||||
temp_config_file = tmp_path / "temp_invokeai.yaml"
|
||||
|
Reference in New Issue
Block a user