Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - Unable to update recipe rating using the API #3578

Closed
6 tasks done
young-hnau opened this issue May 9, 2024 · 1 comment
Closed
6 tasks done

[BUG] - Unable to update recipe rating using the API #3578

young-hnau opened this issue May 9, 2024 · 1 comment
Labels
bug Something isn't working triage

Comments

@young-hnau
Copy link

First Check

  • This is not a feature request.
  • I added a very descriptive title to this issue (title field is above this).
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Mealie documentation, with the integrated search.
  • I already read the docs and didn't find an answer.
  • This issue can be replicated on the demo site (https://demo.mealie.io/).

What is the issue you are experiencing?

Using the API, it is not possible to update the rating for a recipe.

I tested multiple version tags and the error seems to have been introduced in v1.5.0 as the issue is not present in v1.4.0.

I tested against the demo site by GET'ing the recipe `https://demo.mealie.io/api/recipes/amerikanischer-cheesecake' which returned the following:

{
  "id": "15086b14-fa08-4af2-aec6-bf2e932c8f6c",
  "userId": "bf1c62fe-4941-4332-9886-e54e88dbdba0",
  "groupId": "24477569-f6af-4b53-9e3f-6d04b0ca6916",
  "name": "Amerikanischer Cheesecake",
  "slug": "amerikanischer-cheesecake",
  "image": "omYF",
  "recipeYield": "1 serving",
  "totalTime": "2 Stunden",
  "prepTime": "20 Minuten",
  "cookTime": null,
  "performTime": "1 Stunde 40 Minuten",
  "description": "Dieses Cheesecake-Rezept ist für Topfenbegeisterte sicherlich die beste Wahl!",
  "recipeCategory": [],
  "tags": [
    {
      "id": "9bcc84a7-9999-493e-94ae-631fbf0e421e",
      "name": "Amerikanischer Cheesecake",
      "slug": "amerikanischer-cheesecake"
    },
    {
      "id": "eded0747-3a2e-4843-b61e-c2c9e36f86cb",
      "name": "Topfenkuchen - Käsekuchen",
      "slug": "topfenkuchen-kasekuchen"
    }
  ],
  "tools": [],
  "rating": null,
  "orgURL": "https://www.gutekueche.at/amerikanischer-cheesecake-rezept-18811",
  "dateAdded": "2024-05-09",
  "dateUpdated": "2024-05-09T10:52:22.944310",
  "createdAt": "2024-05-09T10:45:18.184103",
  "updateAt": "2024-05-09T10:52:22.949160",
  "lastMade": null,
  "recipeIngredient": [
    {
      "quantity": 1.0,
      "unit": null,
      "food": null,
      "note": "100 g Butter",
      "isFood": false,
      "disableAmount": true,
      "display": "100 g Butter",
      "title": null,
      "originalText": null,
      "referenceId": "9b211839-783a-429e-8144-916c98c9f4fb"
    },
    {
      "quantity": 1.0,
      "unit": null,
      "food": null,
      "note": "1 Stk Eidotter",
      "isFood": false,
      "disableAmount": true,
      "display": "1 Stk Eidotter",
      "title": null,
      "originalText": null,
      "referenceId": "2a024eaa-0179-4e08-976d-23fe92a2e9c6"
    },
    {
      "quantity": 1.0,
      "unit": null,
      "food": null,
      "note": "2 Stk Eier",
      "isFood": false,
      "disableAmount": true,
      "display": "2 Stk Eier",
      "title": null,
      "originalText": null,
      "referenceId": "8fa75e11-e295-462a-8ff5-0337d0763485"
    },
    {
      "quantity": 1.0,
      "unit": null,
      "food": null,
      "note": "1 kg Frischkäse (Doppelrahm)",
      "isFood": false,
      "disableAmount": true,
      "display": "1 kg Frischkäse (Doppelrahm)",
      "title": null,
      "originalText": null,
      "referenceId": "7cf50968-1acb-4b03-8f27-1a372de06ac6"
    },
    {
      "quantity": 1.0,
      "unit": null,
      "food": null,
      "note": "60 g Mehl",
      "isFood": false,
      "disableAmount": true,
      "display": "60 g Mehl",
      "title": null,
      "originalText": null,
      "referenceId": "04492cf1-9c4d-4aaa-b5d5-774252348969"
    },
    {
      "quantity": 1.0,
      "unit": null,
      "food": null,
      "note": "250 ml Schlagobers",
      "isFood": false,
      "disableAmount": true,
      "display": "250 ml Schlagobers",
      "title": null,
      "originalText": null,
      "referenceId": "63f55a95-8f9a-4339-9e42-ed1088dba4c3"
    },
    {
      "quantity": 1.0,
      "unit": null,
      "food": null,
      "note": "250 g Topfen",
      "isFood": false,
      "disableAmount": true,
      "display": "250 g Topfen",
      "title": null,
      "originalText": null,
      "referenceId": "66e35474-73c5-4fa5-a4d6-cc3c48e3b044"
    },
    {
      "quantity": 1.0,
      "unit": null,
      "food": null,
      "note": "2 Stk Vanilleschoten",
      "isFood": false,
      "disableAmount": true,
      "display": "2 Stk Vanilleschoten",
      "title": null,
      "originalText": null,
      "referenceId": "e17f6d0d-60c1-4247-9e1b-3c0d387f93b1"
    },
    {
      "quantity": 1.0,
      "unit": null,
      "food": null,
      "note": "250 g Vollkornkekse",
      "isFood": false,
      "disableAmount": true,
      "display": "250 g Vollkornkekse",
      "title": null,
      "originalText": null,
      "referenceId": "140d8d53-4ab5-411b-aa30-b9ebe8955033"
    },
    {
      "quantity": 1.0,
      "unit": null,
      "food": null,
      "note": "3 EL Zucker",
      "isFood": false,
      "disableAmount": true,
      "display": "3 EL Zucker",
      "title": null,
      "originalText": null,
      "referenceId": "b716d4c2-7d5e-42f2-8dec-443d88de723d"
    },
    {
      "quantity": 1.0,
      "unit": null,
      "food": null,
      "note": "250 g Zucker",
      "isFood": false,
      "disableAmount": true,
      "display": "250 g Zucker",
      "title": null,
      "originalText": null,
      "referenceId": "1a73e4b8-ee67-4d1f-bce6-dedef6a5ea3f"
    }
  ],
  "recipeInstructions": [
    {
      "id": "64eeff50-0ef3-4278-8d4e-bd410f87815c",
      "title": "",
      "text": "Schritt 1",
      "ingredientReferences": []
    },
    {
      "id": "0237a83a-43d2-451a-8a84-ff2119e4cee1",
      "title": "",
      "text": "Backofen auf 160 Grad vorheizen und eine Springform mit Butter einfetten.",
      "ingredientReferences": []
    },
    {
      "id": "01aba559-fea6-4a50-8b7c-b648180ceb34",
      "title": "",
      "text": "Schritt 2",
      "ingredientReferences": []
    },
    {
      "id": "c3784263-4721-4b9e-8257-e63a2d2351f4",
      "title": "",
      "text": "Butter in einem Topf erhitzen und mit Keksen und den 3 EL Zucker zu einer bröseligen Masse kneten. Diese Masse in die Springform (Durchmesser 26) streichen und zu einem Boden festdrücken. Zehn Minuten lang bei Ober- und Unterhitze backen und auskühlen lassen.",
      "ingredientReferences": []
    },
    {
      "id": "c98cc9c4-0484-4290-bc18-3d9a0f4f1598",
      "title": "",
      "text": "Schritt 3",
      "ingredientReferences": []
    },
    {
      "id": "2aca00d3-b924-4b37-aba9-7d48c5ca6467",
      "title": "",
      "text": "Den Frischkäse mit dem Topfen fünf Minuten lang cremig schlagen. In einer Schüssel Zucker und Mehl verrühren und die Topfen-Frischkäse-Masse untermengen. Die Eier und den Dotter hinzumischen.",
      "ingredientReferences": []
    },
    {
      "id": "b9afcf68-752b-45c6-bf5e-65a75e81ffdf",
      "title": "",
      "text": "Schritt 4",
      "ingredientReferences": []
    },
    {
      "id": "7f1228bf-4cda-47d3-a652-51cb903e9026",
      "title": "",
      "text": "Aus den Vanilleschoten das Mark kratzen und mit dem geschlagenen Obers unter die Masse rühren. Alles auf dem Tortenboden verteilen und die Torte für etwa 80 bis 90 Minuten backen. In der Springform auskühlen lassen, dann die Springform entfernen und über Nacht kühl stellen und am nächsten Tag genießen!",
      "ingredientReferences": []
    }
  ],
  "nutrition": {
    "calories": null,
    "fatContent": null,
    "proteinContent": null,
    "carbohydrateContent": null,
    "fiberContent": null,
    "sodiumContent": null,
    "sugarContent": null
  },
  "settings": {
    "public": true,
    "showNutrition": false,
    "showAssets": false,
    "landscapeView": false,
    "disableComments": false,
    "disableAmount": true,
    "locked": false
  },
  "assets": [],
  "notes": [],
  "extras": {},
  "comments": []
}

I then copy/pasted the returned JSON into a PUT request and changed only the rating such as:

{
  ...
  "tools": [],
  "rating": 1,
  "orgURL": "https://www.gutekueche.at/amerikanischer-cheesecake-rezept-18811",
   ...
}

The response from this PUT request still contains "rating": null," and not "rating": 1, as expected. I also tried a PATCH and had the same issue.

As mentioned above, doing the exact same thing in a test environment running v1.4.0 does indeed change the rating to a 1.

Steps to Reproduce

  1. GET https://demo.mealie.io/api/recipes/amerikanischer-cheesecake
  2. Edit JSON response so rating is an int between 1 and 5
  3. PUT the JSON with updated rating back to the same URL
  4. Observe rating has no change

Please provide relevant logs

mealie | DEBUG 2024-05-09T18:47:32 - Calling on_part_begin with no data
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_header_field with data[54:73]
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_header_value with data[75:101]
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_header_end with no data
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_headers_finished with no data
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_part_data with data[105:113]
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_part_end with no data
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_part_begin with no data
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_header_field with data[169:188]
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_header_value with data[190:216]
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_header_end with no data
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_headers_finished with no data
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_part_data with data[220:228]
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_part_end with no data
mealie | DEBUG 2024-05-09T18:47:32 - Calling on_end with no data
mealie | INFO 2024-05-09T18:47:33 - [192.168.65.1:30124] 200 OK "POST /api/auth/token HTTP/1.1"
mealie | INFO 2024-05-09T18:47:40 - [127.0.0.1:58440] 200 OK "GET /api/app/about HTTP/1.1"
mealie | DEBUG 2024-05-09T18:47:45 - Language set to en
mealie | INFO 2024-05-09T18:47:45 - [192.168.65.1:30132] 200 OK "GET /api/recipes/butter-basted-sirloin-steak-with-parsnip-wedges-and-creamed-spinach HTTP/1.1"
mealie | DEBUG 2024-05-09T18:47:53 - Language set to en
mealie | ERROR 2024-05-09T18:47:53 - Unknown Error on recipe controller action
mealie | ERROR 2024-05-09T18:47:53 - Unknown Error on recipe controller action
mealie | ERROR 2024-05-09T18:47:53 - init() missing 1 required positional argument: 'group_id'
mealie | Traceback (most recent call last):
mealie | File "/app/mealie/db/models/_model_utils/helpers.py", line 45, in safe_call
mealie | return func(**get_valid_call(func, dict_args))
mealie | TypeError: init() missing 1 required positional argument: 'group_id'
mealie |
mealie | During handling of the above exception, another exception occurred:
mealie |
mealie | Traceback (most recent call last):
mealie | File "/app/mealie/routes/recipe/recipe_crud_routes.py", line 345, in update_one
mealie | recipe = self.service.update_one(slug, data)
mealie | File "/app/mealie/services/recipe/recipe_service.py", line 355, in update_one
mealie | new_data = self.repos.recipes.update(slug, update_data)
mealie | File "/app/mealie/repos/repository_generic.py", line 191, in update
mealie | entry.update(session=self.session, **new_data)
mealie | File "/app/mealie/db/models/_model_base.py", line 24, in update
mealie | self.init(*args, **kwargs)
mealie | File "", line 6, in init
mealie | File "/app/mealie/db/models/recipe/api_extras.py", line 19, in wrapper
mealie | return func(*args, extras=extras, **kwargs)
mealie | File "/app/mealie/db/models/_model_utils/auto_init.py", line 187, in wrapper
mealie | instances = handle_many_to_many(session, get_attr, relation_cls, val)
mealie | File "/app/mealie/db/models/_model_utils/auto_init.py", line 73, in handle_many_to_many
mealie | return handle_one_to_many_list(session, get_attr, relation_cls, all_elements)
mealie | File "/app/mealie/db/models/_model_utils/auto_init.py", line 100, in handle_one_to_many_list
mealie | new_elems = [safe_call(relation_cls, elem.copy(), session=session) for elem in elems_to_create]
mealie | File "/app/mealie/db/models/_model_utils/auto_init.py", line 100, in
mealie | new_elems = [safe_call(relation_cls, elem.copy(), session=session) for elem in elems_to_create]
mealie | File "/app/mealie/db/models/_model_utils/helpers.py", line 47, in safe_call
mealie | return func(**dict_args)
mealie | TypeError: init() missing 1 required positional argument: 'group_id'
mealie | ERROR 2024-05-09T18:47:53 - init() missing 1 required positional argument: 'group_id'
mealie | Traceback (most recent call last):
mealie | File "/app/mealie/db/models/_model_utils/helpers.py", line 45, in safe_call
mealie | return func(**get_valid_call(func, dict_args))
mealie | TypeError: init() missing 1 required positional argument: 'group_id'
mealie |
mealie | During handling of the above exception, another exception occurred:
mealie |
mealie | Traceback (most recent call last):
mealie | File "/app/mealie/routes/recipe/recipe_crud_routes.py", line 345, in update_one
mealie | recipe = self.service.update_one(slug, data)
mealie | File "/app/mealie/services/recipe/recipe_service.py", line 355, in update_one
mealie | new_data = self.repos.recipes.update(slug, update_data)
mealie | File "/app/mealie/repos/repository_generic.py", line 191, in update
mealie | entry.update(session=self.session, **new_data)
mealie | File "/app/mealie/db/models/_model_base.py", line 24, in update
mealie | self.init(*args, **kwargs)
mealie | File "", line 6, in init
mealie | File "/app/mealie/db/models/recipe/api_extras.py", line 19, in wrapper
mealie | return func(*args, extras=extras, **kwargs)
mealie | File "/app/mealie/db/models/_model_utils/auto_init.py", line 187, in wrapper
mealie | instances = handle_many_to_many(session, get_attr, relation_cls, val)
mealie | File "/app/mealie/db/models/_model_utils/auto_init.py", line 73, in handle_many_to_many
mealie | return handle_one_to_many_list(session, get_attr, relation_cls, all_elements)
mealie | File "/app/mealie/db/models/_model_utils/auto_init.py", line 100, in handle_one_to_many_list
mealie | new_elems = [safe_call(relation_cls, elem.copy(), session=session) for elem in elems_to_create]
mealie | File "/app/mealie/db/models/_model_utils/auto_init.py", line 100, in
mealie | new_elems = [safe_call(relation_cls, elem.copy(), session=session) for elem in elems_to_create]
mealie | File "/app/mealie/db/models/_model_utils/helpers.py", line 47, in safe_call
mealie | return func(**dict_args)
mealie | TypeError: init() missing 1 required positional argument: 'group_id'
mealie | INFO 2024-05-09T18:47:53 - [192.168.65.1:30140] 500 Internal Server Error "PUT /api/recipes/butter-basted-sirloin-steak-with-parsnip-wedges-and-creamed-spinach HTTP/1.1"
mealie | DEBUG 2024-05-09T18:48:00 - Language set to en
mealie | INFO 2024-05-09T18:48:00 - [192.168.65.1:30148] 200 OK "GET /api/recipes/butter-basted-sirloin-steak-with-parsnip-wedges-and-creamed-spinach HTTP/1.1"
mealie | DEBUG 2024-05-09T18:48:08 - Language set to en
mealie | INFO 2024-05-09T18:48:08 - [192.168.65.1:30149] 200 OK "PUT /api/recipes/butter-basted-sirloin-steak-with-parsnip-wedges-and-creamed-spinach HTTP/1.1"
mealie | INFO 2024-05-09T18:48:10 - [127.0.0.1:50854] 200 OK "GET /api/app/about HTTP/1.1"
mealie | DEBUG 2024-05-09T18:48:13 - Language set to en
mealie | INFO 2024-05-09T18:48:13 - [192.168.65.1:30157] 200 OK "PUT /api/recipes/butter-basted-sirloin-steak-with-parsnip-wedges-and-creamed-spinach HTTP/1.1"
mealie | DEBUG 2024-05-09T18:48:14 - Language set to en
mealie | INFO 2024-05-09T18:48:14 - [192.168.65.1:30158] 200 OK "PUT /api/recipes/butter-basted-sirloin-steak-with-parsnip-wedges-and-creamed-spinach HTTP/1.1"

Mealie Version

Tested on:

  • nightly
  • latest
  • v1.5.0
  • v1.4.0 (working)

Deployment

Docker (Linux)

Additional Deployment Details

No response

@young-hnau young-hnau added bug Something isn't working triage labels May 9, 2024
@young-hnau young-hnau changed the title [BUG] - Unable to update rating using the API [BUG] - Unable to update recipe rating using the API May 9, 2024
@michael-genson
Copy link
Collaborator

Since 1.5 ratings can't be updated directly through the recipe API. This is because they're user-specific.

There is a dedicated endpoint for updating ratings, check out the demo docs. The value that is returned via the recipe API shows the average rating between all users

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

2 participants