fix: import recipe notes from Paprika archives (#8384)

Co-authored-by: Kai Wang <kw491@students.waikato.ac.nz>
This commit is contained in:
Kai WangandKai Wang authored and GitHub committed 2026-09-17 19:35:02 +00:00
1 parent 55822fba24
commit 2fcc1481f0
2 files changed
+41 -3

No files matched your search

+2 -3
View File
@@ -7,8 +7,6 @@ import zipfile
from gzip import GzipFile
from pathlib import Path
from mealie.schema.recipe import RecipeNote
from ._migration_base import BaseMigrator
from .utils.migration_alias import MigrationAlias
@@ -53,7 +51,8 @@ class PaprikaMigrator(BaseMigrator):
MigrationAlias(
key="notes",
alias="notes",
func=lambda x: [z for z in [RecipeNote(title="", text=x) if x else None] if z],
# the cleaner only accepts strings and dicts, so a RecipeNote here is silently dropped
func=lambda x: [{"title": "", "text": x}] if x else [],
),
MigrationAlias(
key="recipeCategory",
@@ -1,5 +1,8 @@
import json
import os
from dataclasses import dataclass, field
from gzip import GzipFile
from io import BytesIO
from pathlib import Path
from tempfile import TemporaryDirectory
from zipfile import ZipFile
@@ -311,3 +314,39 @@ def test_recipekeeper_imports_categories_and_yield(api_client: TestClient, uniqu
recipe = get("baked-salmon-fillets-dijon")
assert [c.name for c in recipe.recipe_category or []] == ["Fish"]
assert recipe.recipe_servings == 4
def test_paprika_imports_notes(api_client: TestClient, unique_user_fn_scoped: TestUser) -> None:
"""Paprika exports carry recipe notes in a `notes` string, which must survive the import."""
unique_user = unique_user_fn_scoped
note_text = "Burnt brandy is brandy that has been flamed to burn off the alcohol."
recipe_json = json.dumps(
{
"name": "Paprika Notes Test",
"ingredients": "1 cup flour\n2 eggs",
"directions": "Mix everything together.",
"notes": note_text,
}
).encode()
archive = BytesIO()
with ZipFile(archive, "w") as zip_file:
gzipped = BytesIO()
with GzipFile(fileobj=gzipped, mode="wb") as gz:
gz.write(recipe_json)
zip_file.writestr("paprika-notes-test.paprikarecipe", gzipped.getvalue())
response = api_client.post(
api_routes.groups_migrations,
data={"migration_type": SupportedMigrations.paprika.value},
files={"archive": archive.getvalue()},
headers=unique_user.token,
)
assert response.status_code == 200
response = api_client.get(api_routes.recipes_slug("paprika-notes-test"), headers=unique_user.token)
recipe = Recipe(**assert_deserialize(response))
assert recipe.notes
assert recipe.notes[0].text == note_text