diff --git a/nomad/app/v1/routers/entries.py b/nomad/app/v1/routers/entries.py index d7c3c7bb864bdd1053e1d7e32ea92f16270a9fa1..d846503f23b5e07536f79fefaba14a22d740a7f8 100644 --- a/nomad/app/v1/routers/entries.py +++ b/nomad/app/v1/routers/entries.py @@ -1126,8 +1126,14 @@ def edit(query: Query, user: User, mongo_update: Dict[str, Any] = None, re_index with utils.timer(logger, 'edit elastic update executed', size=len(entry_ids)): if re_index: updated_metadata: List[datamodel.EntryMetadata] = [] + # TODO: Quick and dirty, should remove + updated_entry_fields = {k: v for k, v in mongo_update.items() if not k.startswith('metadata__')} for calc in proc.Calc.objects(calc_id__in=entry_ids): - updated_metadata.append(calc.mongo_metadata(calc.upload)) + entry_metadata = calc.mongo_metadata(calc.upload) + # Ensure that updated fields are marked as "set", even if they are cleared + entry_metadata.m_update_from_dict(updated_entry_fields) + # Add to list + updated_metadata.append(entry_metadata) failed = es_update_metadata(updated_metadata, update_materials=True, refresh=True) @@ -1214,8 +1220,11 @@ async def post_entry_metadata_edit( verify_reference = None if isinstance(quantity.type, metainfo.Reference): verify_reference = quantity.type.target_section_def.section_cls - - mongo_key = 'metadata__%s' % quantity.name + # TODO: quick and dirty, we are anyway rewriting this soon + if quantity.categories and datamodel.MongoMetadata.m_def in quantity.categories: + mongo_key = 'metadata__%s' % quantity.name + else: + mongo_key = quantity.name has_error = False for action in quantity_actions: action.success = True diff --git a/nomad/datamodel/datamodel.py b/nomad/datamodel/datamodel.py index ccf133d4361cd9918f9d96f5f9da7e59c81d9052..35242c7481690c25658ad3371a85d140db8cab0d 100644 --- a/nomad/datamodel/datamodel.py +++ b/nomad/datamodel/datamodel.py @@ -487,7 +487,7 @@ class EntryMetadata(metainfo.MSection): a_elasticsearch=Elasticsearch()) comment = metainfo.Quantity( - type=str, categories=[MongoMetadata, EditableUserMetadata], + type=str, categories=[MongoEntryMetadata, EditableUserMetadata], description='A user provided comment for this entry', a_elasticsearch=Elasticsearch(mapping='text')) diff --git a/nomad/processing/data.py b/nomad/processing/data.py index c9a38477dd86cf61b6437604e96ffe6ec4762a81..f5da3d3acfe96508f59c4785e0f9fc3d756e230b 100644 --- a/nomad/processing/data.py +++ b/nomad/processing/data.py @@ -160,16 +160,17 @@ class Calc(Proc): calc_id: the calc_id of this calc calc_hash: the hash of the entry files entry_create_time: the date and time of the creation of the entry - last_processing_time: the date and time of the last processing. + last_processing_time: the date and time of the last processing last_edit_time: the date and time the user metadata was last edited mainfile: the mainfile (including path in upload) that was used to create this calc parser_name: the name of the parser used to process this calc pid: the legacy NOMAD pid of the entry - external_id: A user provided external id. Usually the id for an entry in an - external database where the data was imported from. + external_id: a user provided external id. Usually the id for an entry in an + external database where the data was imported from external_db: the repository or external database where the original data resides - nomad_version: The NOMAD version used for the last processing - nomad_commit: The NOMAD commit used for the last processing + nomad_version: the NOMAD version used for the last processing + nomad_commit: the NOMAD commit used for the last processing + comment: a user provided comment for this entry metadata: the metadata record wit calc and user metadata, see :class:`EntryMetadata` ''' @@ -186,6 +187,7 @@ class Calc(Proc): external_db = StringField() nomad_version = StringField() nomad_commit = StringField() + comment = StringField() metadata = DictField() # Stores user provided metadata and system metadata (not archive metadata) diff --git a/tests/test_cli.py b/tests/test_cli.py index 4a57a729c4449b76dbd72604f68c1edd82846601..28fccc05053e158cfed6839d0d8a2abe14d4eef4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -198,7 +198,7 @@ class TestAdminUploads: def test_index(self, published): upload_id = published.upload_id calc = Calc.objects(upload_id=upload_id).first() - calc.metadata['comment'] = 'specific' + calc.comment = 'specific' calc.save() assert search(owner='all', query=dict(comment='specific')).pagination.total == 0