Merge pull request #664 from willmiao/codex/remove-recipevalidationerror-on-empty-lora_matches

Allow widget recipe saves without LoRA matches
This commit is contained in:
pixelpaws
2025-11-13 16:22:57 +08:00
committed by GitHub
2 changed files with 42 additions and 2 deletions

View File

@@ -295,8 +295,6 @@ class RecipePersistenceService:
lora_stack = metadata.get("loras", "")
lora_matches = re.findall(r"<lora:([^:]+):([^>]+)>", lora_stack)
if not lora_matches:
raise RecipeValidationError("No LoRAs found in the generation metadata")
loras_data = []
base_model_counts: Dict[str, int] = {}

View File

@@ -155,3 +155,45 @@ async def test_save_recipe_reports_duplicates(tmp_path):
expected_image_path = os.path.normpath(result.payload["image_path"])
assert stored["file_path"] == expected_image_path
assert service._exif_utils.appended[0] == expected_image_path
@pytest.mark.asyncio
async def test_save_recipe_from_widget_allows_empty_lora(tmp_path):
exif_utils = DummyExifUtils()
class DummyScanner:
def __init__(self, root):
self.recipes_dir = str(root)
self.added = []
async def get_local_lora(self, name): # pragma: no cover - no lookups expected
return None
async def add_recipe(self, recipe_data):
self.added.append(recipe_data)
scanner = DummyScanner(tmp_path)
service = RecipePersistenceService(
exif_utils=exif_utils,
card_preview_width=512,
logger=logging.getLogger("test"),
)
metadata = {
"loras": "", # no matches present in the stack
"checkpoint": "base-model.safetensors",
"prompt": "a calm scene",
"negative_prompt": "",
}
result = await service.save_recipe_from_widget(
recipe_scanner=scanner,
metadata=metadata,
image_bytes=b"image-bytes",
)
stored = json.loads(Path(result.payload["json_path"]).read_text())
assert stored["loras"] == []
assert stored["title"] == "recipe"
assert scanner.added and scanner.added[0]["loras"] == []