Closed jakguru closed 4 hours ago
Are you able to reproduce this on the demo?
https://demo.mealie.io/
https://demo.mealie.io/docs
The demo uses the nightly version. We may have fixed this already, but nightly is currently far ahead of beta5 so it may not be in that release.
I have the same issue, running the latest nightly version.
Confirmed this still exists, running up to date mealie-next branch.
Did testing via swagger (URL/docs/
).. created the recipe per these screenshots:
Then did the PUT with the same request body as the OP, with only the groupId and userId changed:
Got a 500 response where Swagger didn't reveal too much, but my docker logs did:
mealie-dev | ERROR: 24-Oct-23 09:38:53 __init__() missing 1 required positional argument: 'group_id'
mealie-dev | Traceback (most recent call last):
mealie-dev | File "/app/mealie/db/models/_model_utils/helpers.py", line 42, in safe_call
mealie-dev | return func(**get_valid_call(func, dict_args))
mealie-dev | TypeError: __init__() missing 1 required positional argument: 'group_id'
mealie-dev |
mealie-dev | During handling of the above exception, another exception occurred:
mealie-dev |
mealie-dev | Traceback (most recent call last):
mealie-dev | File "/app/mealie/routes/recipe/recipe_crud_routes.py", line 339, in update_one
mealie-dev | recipe = self.service.update_one(slug, data)
mealie-dev | File "/app/mealie/services/recipe/recipe_service.py", line 342, in update_one
mealie-dev | new_data = self.repos.recipes.update(slug, update_data)
mealie-dev | File "/app/mealie/repos/repository_generic.py", line 208, in update
mealie-dev | entry.update(session=self.session, **new_data)
mealie-dev | File "/app/mealie/db/models/_model_base.py", line 24, in update
mealie-dev | self.__init__(*args, **kwarg)
mealie-dev | File "<string>", line 6, in __init__
mealie-dev | File "/app/mealie/db/models/recipe/api_extras.py", line 19, in wrapper
mealie-dev | return func(*args, extras=extras, **kwargs)
mealie-dev | File "/app/mealie/db/models/_model_utils/auto_init.py", line 187, in wrapper
mealie-dev | instances = handle_many_to_many(session, get_attr, relation_cls, val)
mealie-dev | File "/app/mealie/db/models/_model_utils/auto_init.py", line 73, in handle_many_to_many
mealie-dev | return handle_one_to_many_list(session, get_attr, relation_cls, all_elements)
mealie-dev | File "/app/mealie/db/models/_model_utils/auto_init.py", line 100, in handle_one_to_many_list
mealie-dev | new_elems = [safe_call(relation_cls, elem, session=session) for elem in elems_to_create]
mealie-dev | File "/app/mealie/db/models/_model_utils/auto_init.py", line 100, in <listcomp>
mealie-dev | new_elems = [safe_call(relation_cls, elem, session=session) for elem in elems_to_create]
mealie-dev | File "/app/mealie/db/models/_model_utils/helpers.py", line 44, in safe_call
mealie-dev | return func(**dict_args)
mealie-dev | TypeError: __init__() missing 1 required positional argument: 'group_id'
mealie-dev | INFO: 192.168.2.153:0 - "PUT /api/recipes/sausage-mixed-grill?group_id=7a267ccc-f55d-4328-a356-121bc2c0e1c2 HTTP/1.1" 500 Internal Server Error```
I also had this error on the latest nightly, and traced it back to the recipeCategory
and tags
fields.
I don't know the technical details (or how it relates to group_id
in the error), but from what I can gather, the error occurs when trying to set one of those fields to anything other than a RecipeCategory
/RecipeTag
type object respectively. These are seen in the schema part of the docs:
For example, since the original query is trying to tag the recipe with tags such as "Dinner" and "Pork", those tags must already exist within Mealie and you must refer to them using it's full identity:
"tags": [
{'id': '6becb67b-a3bd-49d8-81f5-5c770bff079c', 'name': "Dinner", 'slug': 'dinner'},
...
]
Just passing "Dinner" seems to throw the error, even if "Dinner" exists in Mealie.
A workaround I have found while working on a similar importer is
# Request tags from Mealie and cache them, this way we don't have to ask Mealie if a tag already exists each time
tag_cache = requests.get(base_url + "/api/organizers/tags?perPage=100", headers=headers).json()["items"]
# ...
def get_tag_by_name(name):
# If the requested tag already exists in Mealie, use that
cached = [tag for tag in tag_cache if tag["name"] == name]
if len(cached) > 0:
return cached[0]
# If it's not cached (i.e. doesn't exist yet), create it in Mealie and add it to the cache
created_tag = requests.post(base_url + "/api/organizers/tags", json={"name": name}, headers=headers).json()
tag_cache .append(created_tag)
return created_tag
# ...
# Then when constructing the object that is sent to Mealie
tags = [get_tag_by_name(tag) for tag in tag_strings]
...and then basically duplicated for categories
It works, but is certainly less convenient than just passing Mealie the category/tag names
Going to close this. Reviewing what @Dylancyclone had said and confirming with the API spec we do require that full objects for tags and categories so it is an issue with your payload.
I agree that it would be nice if Mealie handled this automatically, but it doesn't at the moment. If anyone want to look into a PR to handle this I'm sure it would be welcome!
First Check
What is the issue you are experiencing?
I am attempting to create a new recipe using the API. I first parse the ingredients via the ingredients parser using the
/api/parser/ingredients
endpoint, and then create the recipe using the/api/recipes
endpoint.When i then try to update the recipe via the
PUT
/api/recipes/{slug}
endpoint with the following payload:I get an HTTP 500 error with the following error in response:
I looked at the console output from the API service and saw the error corresponded with the following log entries:
I am not experienced enough with Python to be able to further debug the issue. I would appreciate any assistance in getting this request to work, since it's 1 of over 200 recipes that I would like to import from Harris Teeter's recipe site (since that's our local grocery market)
You can see the entire script that I'm using (with some details obfuscated) here Once I have a working version, I will be happy to release a cleaner & more optimized version of the script to the community.
Deployment
Docker (Linux)
Deployment Details
Deployed using docker-compose via Portainer with the following versions:
mealie-frontend image: hkotel/mealie:frontend-v1.0.0beta-5 mealie-api image: hkotel/mealie:api-v1.0.0beta-5