Open manuelma opened 11 months ago
I found out that when importing scenario-alternatives, we import all necessary scenarios and alternatives. That has two problems in my opinion:
So if nobody disagrees I will disable importing scenarios and alternatives automatically when importing scenario-alternatives. It will be controlled by a keyword argument or something like that. Any thoughts @jkiviluo @soininen ?
Can you clarify:
In my view, that last one should be controlled by the user (to keep typos at bay using b). Is this what you were also thinking?
when importing just alternative, then only alternative will be imported. I think this is desired behaviour. Is it happening?
Yes
when importing scenarios, one cannot meaningfully import a scenario without importing dependent alternatives. So, if one or more of the dependent alternatives is missing, then we should either a) create the missing alternatives, b) raise an error.
One can add a scenario without any alternatives (add_scenario_item). The scenario_alternative items are added later on via a separate method (add_scenario_alternative_item).
The same should be valid for import, otherwise it's just weird. You should import your scenario, alternative, and scenario_alternative items individually.
Right. I was just thinking of a scenario where one is copying from one DB to another. However, you probably mean that when one is programmatically creating scenarios, then one could make the scenario first and only then add the scenario_alternatives. So, yes, there should be an option to not import associated scenario-alternatives, when importing scenarios. And the default API behaviour should be the same as elsewhere (do not import dependents automatically). In the importer tool the default might be other way around (since it usually makes sense to get the alternatives with the scenario - the alternatives are what really form the scenario).
We should indeed be consistent i.e. not create non-existent alternatives when adding scenario-alternatives by default.
The idea is e.g. when adding a parameter value for an entity or parameter definition that don't exist yet, the entity and parameter definition get optionally created - in other words, anything needed so the parameter value can exist.
So this should be controlled via an additional keyword argument for add_item and also for add_update_item.
At the moment, the ImportMapping class provides this functionality for some of the items (entities and entity groups) but not for all. After this change then, the ImportMapping should be using the new convenience developed.