Skip to content

Commit cc8da6b

Browse files
author
Marin Visscher
committed
Edge deletion when input or output is missing
1 parent 0d9a0ce commit cc8da6b

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

bw_functional/edge_classes.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from logging import getLogger
22
from copy import deepcopy
33

4-
from bw2data import projects, databases
4+
from bw2data import projects, databases, errors
55
from bw2data.backends.proxies import Exchange, Exchanges, ExchangeDataset
66

77
log = getLogger(__name__)
@@ -145,13 +145,19 @@ def delete(self, signal: bool = True):
145145
signal (bool, optional): Whether to send a signal after deletion. Defaults to True.
146146
"""
147147
from .node_classes import Product, Process, MFActivity
148+
149+
try:
150+
function = self.input
151+
process = self.output
152+
except errors.UnknownObject:
153+
log.warning(f"Could not retrieve input or output for exchange deletion. {self['input']=}, {self['output']=}")
154+
super().delete(signal)
155+
return
156+
148157
log.debug(f"Deleting {self['type']} Exchange: {self}")
149158

150159
super().delete(signal)
151160

152-
function = self.input
153-
process = self.output
154-
155161
if not isinstance(process, Process) or not isinstance(function, Product):
156162
return
157163

0 commit comments

Comments
 (0)