spine-tools / Spine-Database-API

Database interface to Spine generic data model
https://www.tools-for-energy-system-modelling.org/
GNU Lesser General Public License v3.0
6 stars 5 forks source link

add_item issues #307

Closed jkiviluo closed 7 months ago

jkiviluo commented 8 months ago

Here's a code that fails on the attached DB (change the path):

import spinedb_api as api
from spinedb_api import DatabaseMapping

url_db_out = "sqlite:///[PATH_TO_DB]/flextool_input_data.sqlite"

parsed_value = api.TimeSeriesFixedResolution(
    api.DateTime("2023-01-01T00:00"),   # start
    "1D",                           # resolution
    [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], # values
    ignore_year=False,
    repeat=False,
)

with DatabaseMapping(url_db_out) as db_flextool:
    value, type_ = api.to_database(parsed_value)
    foo = db_flextool.add_item("parameter_value", check=False,
                                              entity_class_name="node",
                                              parameter_definition_name="inflow",
                                              entity_byname=("east",),
                                              alternative_name="east",
                                              value=value,
                                              type=type_)

The code works if check=True

Other issues to improve:

flextool_input_data.txt

manuelma commented 7 months ago

This is supposed to fail - check=False assumes all the reference ids are provided by the client. I think we should undocument the keyword argument and keep it only for internal purposes.