Sample ID base class not showing lab_id in entries search and self referencing not working

I wrote the following sample ID base class for be inherited in yaml based schemas:

class SampleID(ArchiveSection):
   ''' A ELN base section that can be used for sample IDs.
   If the `sample_owner`, `sample_short_name`, `ìnstitute`, and `creation_datetime`
   quantities are provided, the sample_id will be automatically created as a combination
   of these four quantities.'''

   # m_def = Section(
   #     a_eln=dict(hide=['name', 'lab_id']))

   institute = Quantity(
       type=str,
       description='Alias/short name of the home institute of the owner, i.e. *HZB*.',
       a_eln=dict(component='StringEditQuantity'))

   sample_owner = Quantity(
       type=str,
       shape=[],
       description='Name or alias of the process operator, e.g. jmp',
       a_eln=dict(component='StringEditQuantity'))

   creation_datetime = Quantity(
       type=Datetime,
       description='Creation date of the sample.',
       a_eln=dict(component='DateTimeEditQuantity'))

   sample_short_name = Quantity(
       type=str,
       description='''A short name of the sample (the identifier scribed on the smaple,
        or in the sample container), e.g. 4001-8, YAG-2-34.
        This is to be managed and decided internally by the labs,
        although we recomend to avoid the following characters on it: "_", "/", "\" and "."''',
       a_eln=dict(component='StringEditQuantity'))

   sample_id = Quantity(
       type=str,
       description='''Full sample id. Ideally a human readable sample id convention,
       which is simple, understandable and still having chances of becoming unique.
       If the `sample_owner`, `sample_short_name`, `ìnstitute`, and `creation_datetime`
       are provided, this will be formed automatically by joining these components by an underscore (_).
       Spaces in any of the individual components will be replaced with hyphens (-).
       An example would be hzb_oah_20200602_4001-08''',
       a_eln=dict(component='StringEditQuantity'))

   children = Quantity(
       type=Reference(SectionProxy('SampleID')),
       shape=["*"],
       descriptions='A reference to a sample which are children of this one.',
       a_eln=dict(component='ReferenceEditQuantity'))

   parents = Quantity(
       type=Reference(SectionProxy('SampleID')),
       descriptions='A reference to sample which are parents of this one.',
       a_eln=dict(component='ReferenceEditQuantity'))

   def normalize(self, archive, logger):
       super().normalize(archive, logger)

       if self.institute and self.sample_short_name and self.sample_owner and self.creation_datetime:
           creation_date = self.creation_datetime.strftime('%Y%m%d')
           sample_owner = self.sample_owner.replace(' ', '-')
           sample_id_list = [self.institute, sample_owner, creation_date, self.sample_short_name]
           self.sample_id = '_'.join(sample_id_list)

       if isinstance(self, EntryData):
           if archive.data == self and self.sample_id:
               archive.metadata.entry_name = self.sample_id.replace('_', ' ')
           EntryData.normalize(self, archive, logger)

       if not archive.results:
           archive.results = Results(eln=ELN())
       if not archive.results.eln:
           archive.results.eln = ELN()

       if self.sample_id:
           if archive.results.eln.lab_ids is None:
               archive.results.eln.lab_ids = []
           archive.results.eln.lab_ids.append(self.sample_id)

       if not archive.results.eln.sections:
           archive.results.eln.sections = []
       archive.results.eln.sections.append(self.m_def.name)

The references in children and parents are not working. Additionally, it seems like archive.results.eln.lab_ids does not get populated, or at least I cannot search for the sample id in the entries search in that field.

To reproduce, working in this branch: https://gitlab.mpcdf.mpg.de/nomad-lab/nomad-FAIR/-/tree/Sample_id_baseclass and with the attached yaml schema:

sample_id_test.schema.archive.yaml

Assignee Loading
Time tracking Loading