diff --git a/bw2data/parameters.py b/bw2data/parameters.py index 4ff73996..1fb8267c 100644 --- a/bw2data/parameters.py +++ b/bw2data/parameters.py @@ -1284,7 +1284,8 @@ def add_to_group(self, group, activity): Group.get_or_create(name=group) activity = get_activity((activity[0], activity[1])) - if 'parameters' not in activity: + formula_exchanges = [e for e in activity.exchanges() if "formula" in e] + if 'parameters' not in activity and not any(formula_exchanges): return # Avoid duplicate by deleting existing parameters @@ -1311,11 +1312,15 @@ def reformat(o): ActivityParameter.create(**row) # Parameters are now "active", remove from `Activity` - del activity['parameters'] - activity.save() + if "parameters" in activity: + del activity['parameters'] + activity.save() self.add_exchanges_to_group(group, activity) + # make sure group is re-calculated + Group.get(name=group).expire() + return ActivityParameter.select().where( ActivityParameter.database == activity['database'], ActivityParameter.code == activity['code']