spine-tools / Spine-Toolbox

Spine Toolbox is an open source Python package to manage data, scenarios and workflows for modelling and simulation. You can have your local workflow, but work as a team through version control and SQL databases.
https://www.tools-for-energy-system-modelling.org/
GNU Lesser General Public License v3.0
70 stars 17 forks source link

Gdx does not support anonymous table #1483

Closed manuelma closed 3 years ago

manuelma commented 3 years ago

Maybe I found something:

  1. Create an exporter spec with Gdx and no table name
  2. Run the exporter
Traceback (most recent call last):
  File "/home/manuelma/Codes/spine/data/spinedb_api/spine_io/exporters/writer.py", line 121, in _new_table
    table_started = writer.start_table(table_name, title_key)
  File "/home/manuelma/Codes/spine/data/spinedb_api/spine_io/exporters/gdx_writer.py", line 69, in start_table
    raise WriterException("Gdx does not support anonymous tables.")
spinedb_api.spine_io.exporters.writer.WriterException: Gdx does not support anonymous tables.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/manuelma/miniconda3/envs/spinetoolbox/lib/python3.8/site-packages/gdx2py/gams.py", line 47, in __init__
    first_key = next(iter(keys))
TypeError: 'NoneType' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/manuelma/miniconda3/envs/spinetoolbox/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/manuelma/Codes/spine/engine/spine_engine/utils/returning_process.py", line 41, in run
    result = self._target(*self._args, **self._kwargs)
  File "/home/manuelma/Codes/spine/items/spine_items/exporter/do_work.py", line 71, in do_work
    write(database_map, writer, *mappings, empty_data_header=header_always)
  File "/home/manuelma/Codes/spine/data/spinedb_api/spine_io/exporters/writer.py", line 40, in write
    with _new_table(writer, title, title_key) as table_started:
  File "/home/manuelma/miniconda3/envs/spinetoolbox/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/home/manuelma/Codes/spine/data/spinedb_api/spine_io/exporters/writer.py", line 124, in _new_table
    writer.finish_table()
  File "/home/manuelma/Codes/spine/data/spinedb_api/spine_io/exporters/gdx_writer.py", line 58, in finish_table
    set_ = GAMSSet(self._current_table, self._dimensions)
  File "/home/manuelma/miniconda3/envs/spinetoolbox/lib/python3.8/site-packages/gdx2py/gams.py", line 120, in __init__
    super().__init__(keys, domain, expl_text)
  File "/home/manuelma/miniconda3/envs/spinetoolbox/lib/python3.8/site-packages/gdx2py/gams.py", line 49, in __init__
    raise ValueError("Keys must be a sequence")
ValueError: Keys must be a sequence

Thoughts @soininen ?

soininen commented 3 years ago

As it says in the first Traceback: Gdx does not support anonymous tables.

I guess we could crash a bit more gracefully, though.

soininen commented 3 years ago

Turns out this was actually a bug in GdxWriter. Should be fixed now.