FMPy icon indicating copy to clipboard operation
FMPy copied to clipboard

KeyError in ssp-simulate

Open beutlich opened this issue 2 years ago • 0 comments

On Python 3.7, python -m fmpy.ssp.simulate Example_eDrive.ssp may fail with

Traceback (most recent call last):
  File "C:\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Projekte\FMPy_Test\.venv\lib\site-packages\fmpy\ssp\simulate.py", line 27, in <module>
    result = simulate_ssp(args.ssp_filename, stop_time=args.stop_time)
  File "C:\Projekte\FMPy_Test\.venv\lib\site-packages\fmpy\ssp\simulation.py", line 169, in simulate_ssp
    a = connections_reversed[a]
KeyError: Connector (name: w_out, kind: output)

because dictionary access is nt fail-proof in https://github.com/CATIA-Systems/FMPy/blob/b84238dcfa416e14694fc6b3650347208033dc0d/fmpy/ssp/simulation.py#L168-L169

Should it be

        while isinstance(a.parent, System) and a.parent.parent is not None and a in connections_reversed:
            a = connections_reversed[a]

?

beutlich avatar Mar 14 '23 18:03 beutlich