Skip to content

Fix imported viewer representation arrays - #766

Open
cpignedoli wants to merge 1 commit into
masterfrom
fix/structure-viewer-representation-style-id
Open

Fix imported viewer representation arrays#766
cpignedoli wants to merge 1 commit into
masterfrom
fix/structure-viewer-representation-style-id

Conversation

@cpignedoli

Copy link
Copy Markdown
Member

Summary

Fix a structure-viewer crash when an incoming ase.Atoms object already contains an _aiidalab_viewer_representation_* array that is not present in the current viewer representation list.

Root Cause

StructureDataViewer._observe_structure correctly iterated over the incoming representation style_id, but the unknown-representation branch tried to read structure.arrays[self.style_id]. StructureDataViewer has no style_id attribute, so importing/changing to a structure carrying representation arrays raised AttributeError.

This can happen in downstream apps when a structure previously modified by representation controls is reused or when switching between structures after applying custom representations.

Changes

  • Use the local style_id when importing an unknown representation array.
  • Iterate over a copied list of structure array names when removing stale representation arrays, so deletion during cleanup is safe.
  • Add a regression test for assigning a structure with an unknown representation array.

Validation

  • python -m pytest tests/test_viewers.py::test_structure_data_viewer_imports_unknown_representation_array tests/test_viewers.py::test_structure_data_viewer_representation
  • python -m pytest tests/test_viewers.py

Implemented with Codex.

@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.18%. Comparing base (42ac05e) to head (ad69daf).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #766      +/-   ##
==========================================
+ Coverage   85.03%   85.18%   +0.14%     
==========================================
  Files          18       18              
  Lines        3335     3335              
==========================================
+ Hits         2836     2841       +5     
+ Misses        499      494       -5     
Flag Coverage Δ
python-3.12 85.15% <100.00%> (+0.20%) ⬆️
python-3.9 85.17% <100.00%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cpignedoli
cpignedoli requested a review from yakutovicha June 24, 2026 12:47
@cpignedoli
cpignedoli marked this pull request as ready for review June 24, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant