Skip to content

Commit

Permalink
make sure formulas in exchanges are evaluated even when they do no co…
Browse files Browse the repository at this point in the history
…ntain any parameters
  • Loading branch information
Benjamin W. Portner committed Feb 16, 2023
1 parent bd84bb6 commit 903be83
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions bw2data/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']
Expand Down

0 comments on commit 903be83

Please sign in to comment.