Fix: Handle measuring_point fields correctly in Thing creation API#265
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where creating wells via the API with measuring_point_height and measuring_point_description fields caused an AttributeError. These fields are read-only properties that retrieve data from the MeasuringPointHistory table rather than direct database columns on the Thing model. The fix aligns the API service layer with the existing pattern used in transfer scripts by extracting these fields before Thing creation and creating a separate MeasuringPointHistory record afterward.
Key changes:
- Modified
add_thing()inservices/thing_helper.pyto handle measuring point fields separately - Added test case to verify wells can be created with measuring point data via the API
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests.
|
jirhiker
approved these changes
Nov 29, 2025
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.
Problem
Creating a well via the API with
measuring_point_heightandmeasuring_point_descriptionfails with:AttributeError: property 'measuring_point_height' of 'Thing' object has no setter
This bug was latent in the codebase but only surfaced when API endpoints were called with these fields in the payload.
Root Cause
measuring_point_heightandmeasuring_point_descriptionare not database columns on theThingmodel. They are@propertymethods that retrieve the current value from theMeasuringPointHistorytable. Properties without setterscannot be assigned during object construction.
The transfer scripts (
transfers/well_transfer.py) already handle this correctly by:MeasuringPointHistoryrecords after Thing creation (lines 371-378)However, the API service layer (
services/thing_helper.py) was not following this pattern.Solution
Updated
add_thing()inservices/thing_helper.pyto:measuring_point_heightandmeasuring_point_descriptionfrom data dict before Thing creationMeasuringPointHistoryrecord with the extracted valuesChanges:
datetime,ZoneInfo,MeasuringPointHistoryadd_thing()to handle measuring point fields separately (lines 166-190)Testing
Added test
test_add_water_well_with_measuring_point()that:Verified no regressions:
test_validate_hole_depth_well_depthtest_validate_mp_height_hole_depthtest_add_well_screenImpact
Related
This bug was discovered during work on [legacy date field migration], (#264) but is independent of that feature and should be fixed on
mainfirst.