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

Fix TypeError in clean_nutrition function #1043

Merged
merged 4 commits into from
Mar 15, 2022
Merged

Conversation

zackbcom
Copy link
Contributor

@zackbcom zackbcom commented Mar 13, 2022

Fixes #1033
Using this recipe: https://www.marthastewart.com/336792/breaded-chicken-breasts

Changes

  • If sodiumContent is None, it blows up when trying to check if m or g are in the string.
    • Fixed by checking that it's a string before checking if it has substrings.
  • Flake8 and black incompatability
    • fixed with setting igntore to extend-ignore in .flake8 file Source
    • With ignore used it was enabling all the default ignored rules, include the ones below:
      • W503 line break before binary operator
      • W504 line break after binary operator
  • CodeFactor issues are not from my changes.

Testing Artifacts:

Before code fix:

Error:

mealie-api       |   File "/app/mealie/services/scraper/cleaner.py", line 96, in clean_nutrition
mealie-api       |     if "sodiumContent" in nutrition and "m" not in nutrition["sodiumContent"] and "g" in nutrition["sodiumContent"]:
mealie-api       | TypeError: argument of type 'NoneType' is not iterable

After code fix:

Adds recipe.

Before flake8 fix

  if (
      "sodiumContent" in nutrition
      and type(nutrition["sodiumContent"]) == str
      and "m" not in nutrition["sodiumContent"]
      and "g" in nutrition["sodiumContent"]
  ):
mealie/services/scraper/cleaner.py:98:9: W503 line break before binary operator
mealie/services/scraper/cleaner.py:99:9: W503 line break before binary operator
mealie/services/scraper/cleaner.py:100:9: W503 line break before binary operator

Changed to this to fix W503

    if (
        "sodiumContent" in nutrition and
        type(nutrition["sodiumContent"]) == str and
        "m" not in nutrition["sodiumContent"] and 
        "g" in nutrition["sodiumContent"]
    ):
mealie/services/scraper/cleaner.py:102:38: W504 line break after binary operator
mealie/services/scraper/cleaner.py:103:49: W504 line break after binary operator
mealie/services/scraper/cleaner.py:104:47: W504 line break after binary operator

Then recieved 504.

After flake8 fix:

❯ make lint
poetry run black .
All done! ✨ 🍰 ✨
154 files left unchanged.
poetry run black . --check
All done! ✨ 🍰 ✨
154 files would be left unchanged.
poetry run flake8 mealie tests

@netlify
Copy link

netlify bot commented Mar 13, 2022

✔️ Deploy Preview for mealie-docs ready!

🔨 Explore the source changes: d7793da

🔍 Inspect the deploy log: https://app.netlify.com/sites/mealie-docs/deploys/622d7dbd6f8e370008177efe

😎 Browse the preview: https://deploy-preview-1043--mealie-docs.netlify.app

hay-kot added a commit that referenced this pull request Mar 15, 2022
@hay-kot
Copy link
Collaborator

hay-kot commented Mar 15, 2022

Thanks for the detailed comments looks good to me!

I captured these changes for mealie-next in

@hay-kot hay-kot merged commit 6c549ff into mealie-recipes:dev Mar 15, 2022
hay-kot added a commit that referenced this pull request Mar 15, 2022
hay-kot added a commit that referenced this pull request Mar 15, 2022
* capture #1043

* update file format
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

Successfully merging this pull request may close these issues.

can't import particular recipe from url with apparently valid json
2 participants