diff --git a/mealie/db/models/recipe/instruction.py b/mealie/db/models/recipe/instruction.py index 395b5dba9..ea0d11c42 100644 --- a/mealie/db/models/recipe/instruction.py +++ b/mealie/db/models/recipe/instruction.py @@ -38,5 +38,7 @@ class RecipeInstruction(SqlAlchemyBase): ) @auto_init() - def __init__(self, ingredient_references, session, **_) -> None: - self.ingredient_references = [RecipeIngredientRefLink(**ref, session=session) for ref in ingredient_references] + def __init__(self, session, ingredient_references=None, **_) -> None: + self.ingredient_references = [ + RecipeIngredientRefLink(**ref, session=session) for ref in (ingredient_references or []) + ] diff --git a/tests/integration_tests/user_recipe_tests/test_recipe_crud.py b/tests/integration_tests/user_recipe_tests/test_recipe_crud.py index 467cab8b1..9975c8a3c 100644 --- a/tests/integration_tests/user_recipe_tests/test_recipe_crud.py +++ b/tests/integration_tests/user_recipe_tests/test_recipe_crud.py @@ -1389,6 +1389,29 @@ def test_patch_recipe_after_name_changes_without_slug_update(api_client: TestCli assert patched_recipe["description"] == "Translated without changing the stored slug" +def test_patch_recipe_instructions_without_ingredient_references(api_client: TestClient, unique_user: TestUser): + response = api_client.post( + api_routes.recipes, + json={"name": "Patch instructions without refs"}, + headers=unique_user.token, + ) + assert response.status_code == 201 + slug = response.json() + + response = api_client.patch( + api_routes.recipes_slug(slug), + json={"recipeInstructions": [{"text": "Step one."}, {"text": "Step two."}]}, + headers=unique_user.token, + ) + assert response.status_code == 200 + + response = api_client.get(api_routes.recipes_slug(slug), headers=unique_user.token) + assert response.status_code == 200 + recipe = response.json() + assert [step["text"] for step in recipe["recipeInstructions"]] == ["Step one.", "Step two."] + assert all(step["ingredientReferences"] == [] for step in recipe["recipeInstructions"]) + + def test_put_recipe_name_change_updates_slug(api_client: TestClient, unique_user: TestUser): original_name = "Original Recipe Name" renamed_name = "Renamed Recipe Name"