Upload a new stave with add_node calls
Trying to find a way how to upload a new stave subtree.
ConfigDB does not have an API to just upload a dictionary with a new subtree.
It has add_node
and add_to_node
, which operate on individual nodes, taking children=[]
and parents=[]
lists with IDs of the children and parent nodes.
Moreover, it is not clear how to just get the ID of the current latest
runkey, in order to issue the "commit" command.
modified: .gitlab-ci.yml
modified: scripts/test_upload_a_stave.py
Merge request reports
Activity
Filter activity
added 1 commit
- 1798b0da - search method gets you payloads, not the node
added 1 commit
- 210cbe20 - add_node won't work: you cannot set node ID with it
The
ConfigDB
methods inpyconfigdb
are half-baked:- they mostly work on payloads, not on nodes, when we need nodes
- for example,
search
method finds a payload, not a node - and
search_subtree
returns the whole subtree, with everything under it, not just the node ID
- for example,
-
add_node
method asks for the parent node ID. - I.e.
search
andadd_node
just don't work together. - We need to confirm how
stage_commit
works. If you call a bunch ofadd_node
withstage=True
, should you callstage_commit
at the end or something else? With which runkey identifier?
More importantly:
- there is no method to just upload a dictionary as a new child node under some node ID
-
add_node
methods create a separate node, they take lists of IDs of payloads, parents, and children -
add_node
methods don't have an argument to set the ID of the newly created node - and they don't work with
{'reuse_id': <id>}
nodes - so, it's not flexible when you upload an interconnected object, like a stave:
- you have to use
add_node
to contruct the whole object from scratch - there is no easy way to construct the object locally and upload - there is no easy way to deal with the IDs
- you have to use
Edited by Alex Toldaiev- they mostly work on payloads, not on nodes, when we need nodes
added 1 commit
- 7e1183d1 - A workaround for the half-backed ConfigDB add_node etc
It seems to work with the workaround:
# ConfigDB does not provide an API to just upload a dictionary # with payloads and children together. # you have to create nodes one by one. # Hence, our helper function: def add_subtree(configdb, parent_id, subtree: dict, new_id_map={}, to_stage=False): assert isinstance(subtree, dict), f'Not a dict: {subtree}' if 'reuse_id' in subtree: # skip it return if 'type' not in subtree: raise RuntimeError(f'No "type" in {subtree}') # TODO: what to do with "reuse_id" nodes? # TODO: or else, how to set node ID in add_node? # create the root node of this subtree subtree_id = configdb.add_node(subtree['type'], payloads=subtree['payloads'], parents=[{'id': parent_id}], children=[], stage=to_stage) if 'children' not in subtree: raise RuntimeError(f'No "children" in {subtree}') # create children nodes and save their IDs children_ids = [] for child_node in subtree['children']: add_subtree(configdb, subtree_id, child_node, new_id_map) # update the children IDs in the root node configdb.add_to_node(subtree_id, children=children_ids, stage=to_stage) # update the ID current_id = subtree.get('id') new_id_map[current_id] = subtree_id subtree['id'] = subtree_id def update_references(configdb, parent_id, subtree: dict, new_id_map={}, to_stage=False): if 'reuse_id' in subtree: # find the new id of the reference new_id = new_id_map[subtree['reuse_id']] # add it to the node's children configdb.add_to_node(parent_id, children=[new_id], stage=to_stage) # and done return uptodate_id = subtree['id'] for child_node in subtree['children']: update_references(configdb, uptodate_id, child_node, new_id_map, to_stage) id_mapping = {} add_subtree(configDB, staves_tree_id, stave_node, id_mapping) update_references(configDB, staves_tree_id, stave_node, id_mapping)
mentioned in commit a0d33a31
Please register or sign in to reply