hydraplatform / hydra-base

GNU Lesser General Public License v3.0
8 stars 7 forks source link

single objects should be same as when part of a collection #97

Open drheinheimer opened 4 years ago

drheinheimer commented 4 years ago

I have noticed that some (all?) objects are not the same when called individually as when part of a collection. For example: add_node returns a node object that is different than what is return in a network from, e.g., get_network -> network['nodes'][0]. I have also noticed this with template types (single vs. in a template).

This presents a bit of a challenge to manage, and I suggest the structure of objects be the same no matter where they are found, unless modification is requested with some argument.

This makes updating CRUD operations in a GUI particularly challenging. Often, I want to add/change a single element. For example, if I add a node, I want to simply append the newly added node to the list of existing nodes, without having to refactor the node to be consistent with existing nodes.

Here's a specific example:

add_typeattr returns:

{'attr_id': 8, 'unit_id': 137, 'type_id': 6, 'data_type': 'timeseries', 'description': '', 'properties': {}, 'attr_is_var': 'N', 'data_restriction': None}`

In contrast, the same typeattr, when part of a template (in a templatetype), is:

{'cr_date': '2020-01-10 15:19:18', 'description': '', 'unit_id': 137, 'data_type': 'timeseries', 'default_dataset_id': None, 'attr_id': 8, 'properties': {}, 'data_restriction': None, 'attr_is_var': 'N', 'type_id': 6, 'default_dataset': None, 'attr': {'cr_date': '2020-01-10 15:19:18', 'dimension_id': 12, 'id': 8, 'description': None, 'name': 'dsdsdsd'}}

knoxsp commented 4 years ago

This is a fair point.

This also makes the case for unifying return types and content more generally.

For example hydra base returns dict objects, JSONObjects and SQLAlchemy objects for different function calls. This is mainly done for efficiency -- SQLAlchemy objects don't like being altered, so better to put them into a more portable format. This isn't an issue when using the hydra client library, but can be an issue when interfacing with hydra base directly.