Skip to content

select_dimse misaligns metadata.header and metadata.column_to_attr indices #26

@dwikler

Description

@dwikler

in ServiceAttributeModel

consumers of metadata.header and metadata.column_to_attr expect the keys in column_to_attr to line up with the positions in the header list. As soon as we drop columns, the remaining header cells slide left, and the old indices no longer match.

Remap column_to_attr keys to the new header positions to keeps lookup trivial: header[i] ↔ column_to_attr[i]

If keeping the original column indices is important consider storing them in another structure

Change code to:

def _update_metadata_for_dimse(self, dimse_attributes, all_attributes):
    if hasattr(self.metadata, "header") and hasattr(self.metadata, "column_to_attr"):
        all_indices = [k for k, v in self.metadata.column_to_attr.items() if v in all_attributes]
        keep_indices = [k for k, v in self.metadata.column_to_attr.items() if v in dimse_attributes]
        # Build new header and mapping together to ensure alignment
        new_header = []
        new_column_to_attr = {}
        for i, cell in enumerate(self.metadata.header):
            if (i in keep_indices) or (i not in all_indices):
                new_header.append(cell)
                if i in self.metadata.column_to_attr:
                    new_column_to_attr[len(new_header) - 1] = self.metadata.column_to_attr[i]
        self.metadata.header = new_header
        self.metadata.column_to_attr = new_column_to_attr
    elif hasattr(self.metadata, "column_to_attr"):
        self.metadata.column_to_attr = {
            key: value
            for key, value in self.metadata.column_to_attr.items()
            if (value in dimse_attributes) or (value not in all_attributes)
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions