I know what caused the issue. In my code, I always assigned the exchange value to the amount_formula property, regardless of whether the value was a formula/expression (string) or a numeric value (float). This worked in version 2.6.0. However, in version 2.6.1 it stopped working when a float was assigned to the amount_formula property. To make it work, I now need to either convert the number to a string before assigning it to amount_formula, or assign the float to the amount property instead.
Below I enclose the full code to reproduce the issue. The relevant part of the full code is here:
e.amount_formula = float(amount) # doesn't work
e.amount_formula = str(amount) # works
e.amount = float(amount) # works
The full code:
import uuid
import olca_ipc as ipc
import olca_schema as o
from olca_schema import ProcessType
client = ipc.Client(endpoint=8080)
flow_property = client.get(o.FlowProperty, client.find(o.FlowProperty, name="Mass").id)
unit_group = client.get(o.UnitGroup, client.find(o.UnitGroup, name="Units of mass").id)
unit = [u for u in unit_group.units if u.name == "kg"][0]
ref_flow_id = str(uuid.uuid4())
ref_flow = o.Flow()
ref_flow.id = ref_flow_id
ref_flow.name = "example product"
ref_flow.flow_type = o.FlowType.PRODUCT_FLOW
ref_factor = o.FlowPropertyFactor()
ref_factor.conversion_factor = 1.0
ref_factor.flow_property = flow_property
ref_factor.is_ref_flow_property = True
ref_flow.flow_properties = [ref_factor]
client.put(ref_flow)
elementary_flow = o.Flow()
elementary_flow.id = str(uuid.uuid4())
elementary_flow.name = "example emission"
elementary_flow.flow_type = o.FlowType.ELEMENTARY_FLOW
elementary_factor = o.FlowPropertyFactor()
elementary_factor.conversion_factor = 1.0
elementary_factor.flow_property = flow_property
elementary_factor.is_ref_flow_property = True
elementary_flow.flow_properties = [elementary_factor]
client.put(elementary_flow)
def exchange(flow, amount=None, formula=None, is_input=False, is_reference=False):
e = o.Exchange()
e.id = str(uuid.uuid4())
e.flow = flow
e.unit = unit
e.is_input = is_input
e.is_quantitative_reference = is_reference
if formula is not None:
e.amount_formula = f"{formula}"
elif amount is not None:
e.amount_formula = float(amount) # doesn't work
e.amount_formula = str(amount) # works
e.amount = float(amount) # works
else:
raise Exception('No formula or amount provided')
return e
process = o.Process()
process.id = str(uuid.uuid4())
process.name = "example process"
process.process_type = ProcessType.UNIT_PROCESS
process.exchanges = [
exchange(ref_flow, amount=1.0, is_reference=True),
exchange(elementary_flow, amount=0.5, is_input=True),
exchange(elementary_flow, formula="a * 2", is_input=True),
]
client.put(process