brightway-lca / bw_hestia_bridge

Consume the HESTIA API in Brightway
https://docs.brightway.dev/projects/hestiabridge/
MIT License
1 stars 0 forks source link

Change behaviour if node is not present on server #47

Closed cswh closed 1 year ago

cswh commented 1 year ago

When not setting use_staging to True the following occurs:

>>> import bw_hestia_bridge as bhb
>>> bhb.get_hestia_node("zcuqxv54gn2x")
Traceback (most recent call last):
  File "miniconda3\envs\hestia\lib\site-packages\IPython\core\interactiveshell.py", line 3442, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-16-a0f08a0feebb>", line 1, in <module>
    bhb.get_hestia_node("zcuqxv54gn2x")
  File "hestia\bw_hestia_bridge\bw_hestia_bridge\hestia_api\querying.py", line 154, in get_hestia_node
    node_type = node_type or get_node_type(node_id)
  File "hestia\bw_hestia_bridge\bw_hestia_bridge\hestia_api\querying.py", line 169, in get_node_type
    return search_hestia({"@id": node_id}, how="exact")[0]["@type"].lower()
IndexError: list index out of range
>>> bhb.get_cycle_graph("zcuqxv54gn2x")
Traceback (most recent call last):
  File "miniconda3\envs\hestia\lib\site-packages\IPython\core\interactiveshell.py", line 3442, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-17-cbfabe4f7c90>", line 1, in <module>
    bhb.get_cycle_graph("zcuqxv54gn2x")
  File "hestia\bw_hestia_bridge\bw_hestia_bridge\hestia_api\cycle_graph.py", line 48, in get_cycle_graph
    eid = elt["@id"]
TypeError: string indices must be integers

The node with id "zcuqxv54gn2x" only exists on the staging server. It would be helpful to get somehow the information as a return of the called function that the node is not present via the implicitly or explicitly chosen API.

tfardet commented 1 year ago

I'll fix the behavior in get_cycle_graph; however I'm not sure search_hestia requires changes... it returns an empty list when nothing is found... that sounds like an expected behavior to me, does it not?

EDIT, sorry, misread! Will fix that!