ephes / kptncook

Fetch receipts from kptncook API and export them to mealie or paprika
MIT License
39 stars 3 forks source link

Cannot sync with mealie when having recipes from other source #28

Closed m4um4u1 closed 12 months ago

m4um4u1 commented 1 year ago

The script doesnt seem to like it when having recipies in mealie that are not from kptncook. We have a lot of recipies that we added manually or imported from url in our mealie. Is there a way to exclude them form the sync? Because the pydantic validator throws an exeption when theres missing variables like cookingTime or lastMade when syncing. Maybe we could give synced kptncook recepies a orgURL that we can parse in the script so it knows if its a syncable script or not

m4um4u1 commented 1 year ago

I forgot to add the error:

ValidationError: 2 validation errors for Recipe recipe_yield Field required [type=missing, input_value={'id': 'f1219ce4-7521-443...4326', 'lastMade': None}, input_type=dict] For further information visit https://errors.pydantic.dev/2.4/v/missing nutrition Field required [type=missing, input_value={'id': 'f1219ce4-7521-443...4326', 'lastMade': None}, input_type=dict] For further information visit https://errors.pydantic.dev/2.4/v/missing

ephes commented 1 year ago

Thanks for your report!

I have a little bit trouble to reproduce it, since I am not able to run mealie at the moment :). But it should be possible to only compare against the list of recipes from kptncook. I think we add a kptncook tag for each recipe added by kptncook sync.

I'll look into this on the weekend, probably.

m4um4u1 commented 1 year ago

Sounds good, if you need help in any way, just let me know :)

ephes commented 1 year ago

The problem with my broken mealie instance is that the nuxt server process does not seem to forward requests to the fastapi python process. A request to my mealie instances api docs returns a 404 for example and I don't know why. Maybe some issue with the nuxt config, dunno.

Managed to work around this issue by forwarding the fastapi port to my local machine using ssh so I was still able to run kptncook sync against it and immediately could reproduce your issue 😅.

ephes commented 1 year ago

Your issue seems to be caused by the pydantic2 upgrade from last month. In pydantic 1 foo: str | None ment that the foo attribute is optional. In pydantic 2 it now means that it could be None, but is not optional. So I had replace those lines with foo: str | None = None which means foo is optional in pydantic 2, too.

I also now skip recipes failing validation. I'm not really sure whether this is the right approach because now kptncook recipes might become re-added when they cannot be validated as mealie recipes. But just crashing is maybe also not the best approach.

Anyway - the issue from above should be fixed in 0.0.13

m4um4u1 commented 1 year ago

Thanks a lot for your hard work 😊

ca-dmin commented 12 months ago

@ephes

Thanks for your tool 👍

In order for me to sync to Mealie today, I still need to put in a fix:

diff mealie.py.0.0.13 mealie.py
134c134
<     file_name: str | None
---
>     file_name: str | None = None

class RecipeAsset(BaseModel): name: str icon: str file_name: str | None = None

ephes commented 12 months ago

Seems I forgot some lines 😅. Should be fixed in 0.0.14