Skip to content

fix: Use immutable copy pattern for WellItem result attachment#1166

Merged
nathan-stender merged 3 commits into
mainfrom
fix/appbio-quantstudio-immutable-result
Apr 7, 2026
Merged

fix: Use immutable copy pattern for WellItem result attachment#1166
nathan-stender merged 3 commits into
mainfrom
fix/appbio-quantstudio-immutable-result

Conversation

@nathan-stender

Copy link
Copy Markdown
Collaborator

Summary

Resolves P0 TODO #2 from codebase audit by using dataclasses.replace() for immutable result attachment instead of mutating private _result field after construction.

Problem

Previously, WellItem._result was mutated inside _create_measurement() with a TODO comment:

# TODO: temp workaround for cal doc result
well_item._result = result

This violated the intended immutability of the private field. The TODO was added during PR #546 refactor when Result changed from a public mutable field to a private field with property accessor.

Root cause: WellItem and Result data come from different file sections parsed at different times, but calculated documents need access to result data through well items.

Solution

Use dataclasses.replace() to create immutable copies with results attached at the correct point in the data flow:

  1. Parse wells (from "Sample Setup" section)
  2. Parse results (from "Results" section)
  3. Create enriched copies via enrich_wells_with_results() using dataclasses.replace()
  4. Use enriched wells for calculated documents and measurements

Changes

  • Added enrich_wells_with_results() that returns new Well/WellItem instances with results attached
  • Removed TODO and mutation from _create_measurement()
  • Parser now uses enriched_wells for both calculated documents and measurements
  • Clear architectural separation: "wells without results" → "wells with results"

Testing

  • All 27 appbio_quantstudio tests pass
  • All 506 tests pass
  • No golden file changes
  • Linting clean

🤖 Generated with Claude Code

Previously, WellItem._result was mutated after construction inside
_create_measurement(), violating the intended immutability of the
private field. This was a temporary workaround added during the PR #546
refactor when Result was changed from a public mutable field to a
private field with property accessor.

The root issue: WellItem and Result data come from different file
sections and are parsed at different times, but calculated documents
need access to result data through well items.

Solution: Use dataclasses.replace() to create immutable copies of
WellItem with _result properly set at construction time. This avoids
mutation while maintaining the architectural separation between
"wells without results" and "wells with results".

Changes:
- Added enrich_wells_with_results() that returns new Well/WellItem
  instances with results attached via dataclasses.replace()
- Removed TODO and mutation from _create_measurement()
- Parser now uses enriched_wells for both calculated documents and
  measurements

All tests pass, no golden file changes.

Co-Authored-By: Claude Opus 4.1 <noreply@anthropic.com>
@nathan-stender
nathan-stender requested review from a team and slopez-b as code owners April 7, 2026 07:26
@nathan-stender
nathan-stender merged commit a8c5ae1 into main Apr 7, 2026
9 checks passed
@nathan-stender
nathan-stender deleted the fix/appbio-quantstudio-immutable-result branch April 7, 2026 15:26
nathan-stender added a commit that referenced this pull request Apr 8, 2026
### Added

- Add locale-aware timestamp parsing using Babel CLDR data (#1167)
- Add global locale support for number parsing (#1165)
- Reduce Cytiva Biacore T200 Control memory usage with cycle streaming
(#1164)
- Cytiva T200 - Implement streaming decoder to reduce memory usage by
55% (#1163)

### Fixed

- Default to day-first format for invalid/unknown locales (#1168)
- Use immutable copy pattern for WellItem result attachment (#1166)
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.

2 participants