fix: Use immutable copy pattern for WellItem result attachment#1166
Merged
Conversation
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>
ajcariaga16
approved these changes
Apr 7, 2026
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves P0 TODO #2 from codebase audit by using
dataclasses.replace()for immutable result attachment instead of mutating private_resultfield after construction.Problem
Previously,
WellItem._resultwas mutated inside_create_measurement()with a TODO comment: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:enrich_wells_with_results()usingdataclasses.replace()Changes
enrich_wells_with_results()that returns new Well/WellItem instances with results attached_create_measurement()enriched_wellsfor both calculated documents and measurementsTesting
🤖 Generated with Claude Code