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

Fixed two issues adding recipe as ingredient to others #152

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

flochir
Copy link
Contributor

@flochir flochir commented Apr 9, 2023

Adresses two issues in reccard.py preventing a recipe from being added as an ingredient to another one.

Description

Tried adding a recipe as an ingredient to another:
Recipe -> Edit ingredients -> Add recipe

This raised:
Traceback (most recent call last): File "~/gourmand/reccard.py", line 1139, in <lambda> _('Add another recipe as an ingredient in this recipe'), lambda *args: RecSelector(self.rg, self)), File "~/gourmand/src/gourmand/reccard.py", line 2926, in __init__ RecIndex.__init__(self, File "~/gourmand/src/gourmand/recindex.py", line 64, in __init__ self.setup_widgets() File "~/gourmand/src/gourmand/recindex.py", line 139, in setup_widgets self.setup_search_views() File "~/src/gourmand/recindex.py", line 211, in setup_search_views sort_by=self.sort_by) File "~/gourmand/src/gourmand/reccard.py", line 2937, in sort_by column, ascending = preferences.values() ValueError: not enough values to unpack (expected 2, got 1)

Found the culprit in reccard.py, Line 2937, incompatible assignment:
column, ascending = preferences.values()

Fixed that and got a list of recipes to select. Selecting one and choosing an amount yielded a text box
"You haven't selected any recipes!" and after clicking "OK":

Traceback (most recent call last): File "~/gourmand/src/gourmand/reccard.py", line 2977, in rec_tree_select_rec self.ok() File "~/gourmand/src/gourmand/reccard.py", line 2998, in ok self.ingEditor.ingtree_ui.ingController.add_ingredient_from_kwargs( File "~/gourmand/src/gourmand/reccard.py", line 1752, in add_ingredient_from_kwargs self.update_ingredient_row( TypeError: IngredientController.update_ingredient_row() got an unexpected keyword argument 'refid'

Found that compared to older versions, def update_ingredient_row() omitted "refid" in its named parameters. It seemed ok for update_ingredient_row() to not actually handle "refid" as it seems to be done one up in add_ingredient_from_kwargs(), so I just added "refid" back to the parameters.

It seems to work well again. However I observed one new issue: Adding another recipe to the ingredients only, the "Save" button on the containing recipe stays grayed out. Adding and removing any other normal ingredient enables the button. The recipe can then be saved and works including the sub recipe reference.

How Has This Been Tested?

Created two test recipes with one simple ingredient each and yield property "1 Portion". Then tried adding one to the other as sub recipe.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@Zimbelstern
Copy link
Contributor

Thanks, I have successfully patched /usr/lib/python3/dist-packages/gourmand/reccard.py from Debian package 1.1.0+really1.1.0~rc3-3 with line 1779 from your commit.
The changes in line 2938 weren't necessary here, quite the contrary:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/gourmand/reccard.py", line 1139, in <lambda>
    _('Add another recipe as an ingredient in this recipe'), lambda *args: RecSelector(self.rg, self)),
                                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/gourmand/reccard.py", line 2927, in __init__
    RecIndex.__init__(self,
  File "/usr/lib/python3/dist-packages/gourmand/recindex.py", line 64, in __init__
    self.setup_widgets()
  File "/usr/lib/python3/dist-packages/gourmand/recindex.py", line 139, in setup_widgets
    self.setup_search_views()
  File "/usr/lib/python3/dist-packages/gourmand/recindex.py", line 210, in setup_search_views
    self.rvw: List['RowProxy'] = self.rd.search_recipes(self.searches,
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/gourmand/backends/db.py", line 855, in search_recipes
    order_by=make_order_by(sort_by,self.recipe_table,),
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/gourmand/backends/db.py", line 109, in make_order_by
    if isinstance(col.type, Text):
                  ^^^^^^^^
AttributeError: 'str' object has no attribute 'type'

Just FYI – I don't know if this information is important for you. In the development version, everything seems to work fine with both changes.

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.

2 participants