aiida-core icon indicating copy to clipboard operation
aiida-core copied to clipboard

Refactor `MetadataField` parameters: fix semantic overloading and ambiguity

Open GeigerJ2 opened this issue 1 month ago • 1 comments

There are a few potential issues with the current fields and their usage throughout the code:

1. exclude_from_cli overload -> this parameter serves THREE distinct purposes:

  • CLI option construction (cmdline/groups/dynamic.py:174): https://github.com/aiidateam/aiida-core/blob/49af7f0a6908250ee93fb65ba9bb67bc0c055829/src/aiida/cmdline/groups/dynamic.py#L173-L175
  • CLI display output (cmdline/commands/cmd_code.py:242): https://github.com/aiidateam/aiida-core/blob/49af7f0a6908250ee93fb65ba9bb67bc0c055829/src/aiida/cmdline/commands/cmd_code.py#L238-L245
  • YAML export (orm/nodes/data/code/abstract.py:376): https://github.com/aiidateam/aiida-core/blob/49af7f0a6908250ee93fb65ba9bb67bc0c055829/src/aiida/orm/nodes/data/code/abstract.py#L375-L377

2. is_attribute semantic confusion -> this parameter has four conflicting interpretations across the codebase:

  • orm/nodes/node.py: is_attribute=False = "stored in DB columns (not attributes column)"
    • Used for: uuid, node_type, ctime, mtime, label, description, etc. https://github.com/aiidateam/aiida-core/blob/49af7f0a6908250ee93fb65ba9bb67bc0c055829/src/aiida/orm/nodes/node.py#L198-L201
  • orm/nodes/data/code/portable.py: is_attribute=False = "not stored at all, only for construction"
    • filepath_files - used to populate repository, then discarded https://github.com/aiidateam/aiida-core/blob/49af7f0a6908250ee93fb65ba9bb67bc0c055829/src/aiida/orm/nodes/data/code/portable.py#L68-L76
  • orm/nodes/data/dict.py: is_attribute=False = INCORRECT - content IS stored as attributes
    • The value field contradicts its own metadata
    • Implementation uses self.base.attributes.get/set() https://github.com/aiidateam/aiida-core/blob/49af7f0a6908250ee93fb65ba9bb67bc0c055829/src/aiida/orm/nodes/data/dict.py?plain=1#L53-L58
  • .orm/nodes/data/code/installed.py: defaults to is_attribute=True = INCORRECT
    • computer field stored via self.backend_entity.computer, not attributes https://github.com/aiidateam/aiida-core/blob/49af7f0a6908250ee93fb65ba9bb67bc0c055829/src/aiida/orm/nodes/data/code/installed.py?plain=1#L44-L54

3. Additional Issues Found

  • No way to mark fields as "computed/read-only" (like repository_metadata)
  • No distinction between internal implementation details vs user-facing fields
  • The TODO comment at cmd_code.py:248-251 explicitly calls out these issues with Dict and InstalledCode https://github.com/aiidateam/aiida-core/blob/49af7f0a6908250ee93fb65ba9bb67bc0c055829/src/aiida/cmdline/commands/cmd_code.py?plain=1#L247-L257

Impact

The current design makes it impossible to correctly:

  • Show only attribute-stored fields in CLI output (cmd_code.py logic is broken)
  • Distinguish between construction-time vs display-time behavior
  • Accurately represent where/how data is persisted

Ping @edan-bainglass

GeigerJ2 avatar Nov 14 '25 08:11 GeigerJ2