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

FDC ID is not allowed to be empty for new food import #2

Open
mikhail5555 opened this issue Sep 6, 2023 · 0 comments
Open

FDC ID is not allowed to be empty for new food import #2

mikhail5555 opened this issue Sep 6, 2023 · 0 comments

Comments

@mikhail5555
Copy link

Issue:

Some foods don't have an FDC ID, especially produces (In this example Lime Peel)
fdc_id is not nullable which throws a validation error if you try to add a food without it.

https://github.com/TandoorRecipes/open_data_plugin/blob/master/models.py#L114

In some other models it seems to be nullable:
https://github.com/TandoorRecipes/open_data_plugin/blob/master/models.py#L82

Request:

{
   "version":{
      "id":1,
      "name":"base",
      "code":"base"
   },
   "slug":"food-lime-peel-raw",
   "name":"Lime Peel",
   "plural_name":"Lime Peel",
   "store_category":{
      "id":1,
      "version":{
         "id":1,
         "name":"base",
         "code":"base",
         "comment":""
      },
      "slug":"category-produce",
      "name":"Produce",
      "description":"",
      "comment":"Vegetables and fruits. Could be split into those categories.",
      "created_by":"szeraax"
   },
   "preferred_unit_metric":null,
   "preferred_shopping_unit_metric":null,
   "preferred_unit_imperial":null,
   "preferred_shopping_unit_imperial":null,
   "properties":[
      {
         "property":{
            "id":6,
            "version":{
               "id":1,
               "name":"base",
               "code":"base",
               "comment":""
            },
            "slug":"property-carbohydrates",
            "name":"Carbohydrates",
            "unit":"g",
            "fdc_id":1005,
            "comment":"",
            "created_by":"vabene1111"
         },
         "property_amount":"16"
      },
      {
         "property":{
            "id":4,
            "version":{
               "id":1,
               "name":"base",
               "code":"base",
               "comment":""
            },
            "slug":"property-calories",
            "name":"Calories",
            "unit":"kcal",
            "fdc_id":1008,
            "comment":"",
            "created_by":"vabene1111"
         },
         "property_amount":"47"
      },
      {
         "property":{
            "id":5,
            "version":{
               "id":1,
               "name":"base",
               "code":"base",
               "comment":""
            },
            "slug":"property-proteins",
            "name":"Proteins",
            "unit":"g",
            "fdc_id":1003,
            "comment":"",
            "created_by":"vabene1111"
         },
         "property_amount":"1.5"
      },
      {
         "property":{
            "id":7,
            "version":{
               "id":1,
               "name":"base",
               "code":"base",
               "comment":""
            },
            "slug":"property-fats",
            "name":"Fats",
            "unit":"g",
            "fdc_id":1004,
            "comment":"",
            "created_by":"vabene1111"
         },
         "property_amount":"0.3"
      }
   ],
   "fdc_id":"",
   "comment":"",
   "properties_food_amount":"100",
   "properties_food_unit":{
      "id":1,
      "version":{
         "id":1,
         "name":"base",
         "code":"base",
         "comment":""
      },
      "slug":"unit-g",
      "name":"g",
      "plural_name":"g",
      "base_unit":"G",
      "type":"WEIGHT",
      "comment":"",
      "created_by":"vabene1111"
   },
   "properties_source":"Same as food-lemon-peel-raw"
}

Response:

{"fdc_id":["This field may not be blank."]}

Screenshot:
image

Proposed solution:

Make the field nullable for foods that don't have one

@mikhail5555 mikhail5555 changed the title FDC ID is not allowed to be nullable for new food import FDC ID is not allowed to be empty for new food import Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant