PieterMostert / Lipgloss

Python app for creating glaze recipes
GNU General Public License v3.0
5 stars 4 forks source link

Deleting and then creating a new ingredient with the same index #3

Closed PieterMostert closed 6 years ago

PieterMostert commented 7 years ago

If you calculate the restrictions, delete an ingredient (through the ingredient editor; go to Options > Edit Ingredients), and then create a new ingredient which has the same index as the deleted ingredient, you'll get an error the next time you try to calculate the restrictions. The problem boils down to not deleting all references to the ingredient from the PuLP LP problem when you delete the ingredient.

derekphilipau commented 7 years ago

I accidentally deleted Silica, closed Lipgloss, then attempted to re-open. Re-open fails with:

dau-mbp:Lipgloss dau$ python3 GUI.py 
Traceback (most recent call last):
  File "GUI.py", line 511, in <module>
    open_recipe('0', restr_dict)
  File "GUI.py", line 83, in open_recipe
    current_recipe.update_oxides()            # in case the oxide compositions have changed
  File "/Users/dau/Lipgloss/recipes.py", line 114, in update_oxides
    ass_oxides = associated_oxides(self.ingredients)
  File "/Users/dau/Lipgloss/recipes.py", line 41, in associated_oxides
    assoc_oxides = assoc_oxides.union(set(ingredient_compositions[index]))  # update the available oxides. Probably not the most
KeyError: '0'
PieterMostert commented 7 years ago

I'm pretty sure this is due to another bug, which is that whenever you delete an ingredient, it isn't automatically deleted from all recipes that contain it. When you try to open a recipe that still contains a reference to the deleted ingredient, you run into trouble.