cidgoh / DataHarmonizer

A standardized browser-based spreadsheet editor and validator that can be run offline and locally, and which includes templates for SARS-CoV-2 and Monkeypox sampling data. This project, created by the Centre for Infectious Disease Genomics and One Health (CIDGOH), at Simon Fraser University, is now an open-source collaboration with contributions from the National Microbiome Data Collaborative (NMDC), the LinkML development team, and others.
MIT License
91 stars 23 forks source link

Loading a template modifies root slot definitions #382

Closed pkalita-lbl closed 1 year ago

pkalita-lbl commented 1 year ago

When a template is loaded, this code merges together the root-level slot definition with the corresponding slot definition in a class's attribute list: https://github.com/cidgoh/DataHarmonizer/blob/c0010697950b82beb55b8770f393c2344dce46c7/lib/DataHarmonizer.js#L141-L149

The issue is that Object.assign modifies the "target" object (in this case self.schema.slots[name]).

To see the effect of this, consider this schema:

id: http://example.org/test
name: test
imports:
- linkml:types
prefixes:
  linkml: https://w3id.org/linkml/

slots:
  s1:
    range: string

classes:
  C1:
    slots:
      - s1
    slot_usage:
      s1:
        required: true
        title: 'C1:s1'
  C2:
    slots:
      - s1
    slot_usage:
      s1:
        title: 'C2:s1'

When DataHarmonizer first loads the template for C1, the C1:s1 column will be required as expected. However if the template is changed to C2, then the resulting column C2:s1 will also be marked as required, which is incorrect.

ddooley commented 1 year ago

Thank you so much for catching that! Tough one to debug perhaps.