Skip to content

Refactor MetadataField parameters: fix semantic overloading and ambiguity #7099

@GeigerJ2

Description

@GeigerJ2

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:

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.
      class Model(Entity.Model):
      uuid: Optional[str] = MetadataField(
      None, description='The UUID of the node', is_attribute=False, exclude_to_orm=True, exclude_from_cli=True
      )
  • orm/nodes/data/code/portable.py: is_attribute=False = "not stored at all, only for construction"
    • filepath_files - used to populate repository, then discarded
      filepath_files: str = MetadataField(
      ...,
      title='Code directory',
      description='Filepath to directory containing code files.',
      short_name='-F',
      is_attribute=False,
      priority=2,
      orm_to_model=_export_filpath_files_from_repo, # type: ignore[arg-type]
      )
  • 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()
      class Model(Data.Model):
      value: t.Dict[str, t.Any] = MetadataField(
      description='Dictionary content.',
      is_attribute=False,
      is_subscriptable=True,
      )
  • .orm/nodes/data/code/installed.py: defaults to is_attribute=True = INCORRECT
    • computer field stored via self.backend_entity.computer, not attributes
      class Model(AbstractCode.Model):
      """Model describing required information to create an instance."""
      computer: str = MetadataField( # type: ignore[assignment]
      ...,
      title='Computer',
      description='The remote computer on which the executable resides.',
      orm_to_model=lambda node, _: cast('InstalledCode', node).computer.label,
      short_name='-Y',
      priority=2,
      )

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
    # Skip fields that are not stored in the attributes column
    # NOTE: this also catches e.g., filepath_files for PortableCode, which is actually a "misuse"
    # of the is_attribute metadata flag, as there it is flagging that the field is not stored at all!
    # TODO (edan-bainglass) consider improving this by introducing a new metadata flag or reworking PortableCode
    # TODO see also Dict and InstalledCode for other potential misuses of is_attribute
    if not get_metadata(
    field_info,
    key='is_attribute',
    default=True,
    ):
    continue

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions