Skip to content

Commit

Permalink
Add EXPERIMENTAL support for updating BlueSkyEventStream descriptors 🧪
Browse files Browse the repository at this point in the history
  • Loading branch information
Kezzsim committed Feb 1, 2024
1 parent ea608e7 commit 8737d3a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions suitcase/mongo_normalized/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ def update(self, name, doc):
The new version of the document. Its uid will be used to match it
to the current version, the one to be updated.
"""
if name in ['start', 'stop']:
key = 'run_start' if name == 'stop' else 'uid'
if name in ['start', 'stop', 'descriptor']:
# Keys and collection names differ slightly between start, stop and descriptor
key = 'uid' if name == 'start' else 'run_start'
name = f'_event_{name}' if name == 'descriptor' else f'_run_{name}'
event_model.schema_validators[event_model.DocumentNames.start].validate(doc)
current_col = getattr(self, f'_run_{name}_collection')
revisions_col = getattr(self, f'_run_{name}_collection_revisions')
current_col = getattr(self, f'{name}_collection')
revisions_col = getattr(self, f'{name}_collection_revisions')
old = current_col.find_one({key: doc[key]})
if (old is None and name == 'stop'):
# New stop document : insert it
if (old is None and (name == '_run_stop' or name == '_event_descriptor')):
# New stop or descriptor document : insert it
current_col.insert_one(doc)
else:
old.pop('_id')
Expand Down

0 comments on commit 8737d3a

Please sign in to comment.