Skip to content

Parameter dependency text replaces every letter 'a' and only understands dependencies keyed 'a' #365

Closed

Description

@rozyczko

Source: EasyReflectometryApp/Backends/Py/logic/parameters.py, _get_dependency_expression (L299-L314 @ 518ab78)

_get_dependency_expression builds the human-readable dependency field of each Analysis parameters row:

if hasattr(param, 'dependency_map') and 'a' in param.dependency_map:
    ...
    return param.dependency_expression.replace('a', dep_name)
return f'= {param.value}'

It has two problems:

  1. str.replace('a', ...) replaces every letter a, not just the variable a. For example, max(a, 0) with a → Instrument scale becomes mInstrument scalex(Instrument scale, 0).
  2. Only a key named exactly a is handled. Constraints made in the app key dependency_map by alias (Sample._extract_dependency_map in sample.py), and the library uses other keys too: rho_m in Layer, t0 … tn for Model.total_thickness. Those rows skip the branch and get = <current value>, so a dynamic constraint is described as a static one.

Impact today: latent. The dependency field is shown only in the Fittables.qml tooltips for derived and inactive rows, and those get their text elsewhere (_DERIVED_DESCRIPTIONS, the inactive notes). The wrong text will appear as soon as dependent rows' dependency is shown in the UI.

Fix: substitute every key of dependency_map with a word-boundary regex (re.sub(rf'\b{re.escape(key)}\b', ...)), as sample.py already does for constraint expressions. Reusing Sample._pretty_expression directly would be even better. Add a test with an expression that contains other a characters, and one with a key other than a.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [priority] low[scope] bug

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions