Skip to content

DataStore serialization has never worked: as_dict returns None, from_dict recurses infinitely #378

@rozyczko

Description

@rozyczko

Summary

src/easyreflectometry/data/data_store.py:59-72, two independent breakages:

def as_dict(self, skip: list = []) -> dict:
    this_dict = super(DataStore, self).as_dict(self, skip=skip)  # passes self twice
    this_dict['items'] = [...]
    # no return -> always None

@classmethod
def from_dict(cls, d):
    items = d['items']
    del d['items']
    obj = cls.from_dict(d)   # calls itself -> infinite recursion

Also a mutable default argument (skip: list = []).

DataStore/ProjectData appear to be legacy — Project manages its own _experiments dict and bespoke _as_dict_add_experiments — yet the classes remain exported and entirely untested (which is why both bugs survive).

Suggested fix

Either delete the dead classes or fix (super().as_dict(skip=skip) + return; super().from_dict(d)) and add round-trip tests. Related fragility in the live path: _as_dict_add_experiments (project.py:896-905) writes experiments_models/experiments_names only inside if experiment.xe is not None:, while _from_dict_extract_experiments (:950-962) reads them (and [key][3]) unconditionally — masked today only because DataSet1D always materializes xe.

Found during deep code review (DEEP_ANALYSIS.md §5.2, §5.3, §5.8).

Metadata

Metadata

Assignees

No one assigned

    Labels

    [priority] mediumNormal/default priority[scope] maintenanceCode/tooling cleanup, no feature or bugfix (major.minor.PATCH)
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions