Skip to content

Validate properties on assignment#278

Open
rwb27 wants to merge 5 commits intomainfrom
validate-properties-on-assignment
Open

Validate properties on assignment#278
rwb27 wants to merge 5 commits intomainfrom
validate-properties-on-assignment

Conversation

@rwb27
Copy link
Collaborator

@rwb27 rwb27 commented Mar 3, 2026

This makes use of the validation logic now added to PropertyInfo to validate properties when they are set from Python. Properties are already validated when set over HTTP.

I've added to existing tests to ensure that we test this in various ways, both by calling __set__ on a mocked Thing and in more realistic contexts.

I have added lt.FEATURE_FLAGS which makes this an opt-in feature. That should mean that we can test against the OFM codebase as-is, and that it should pass when we use a feature branch that enables validation.

It's slightly unfortunate that this PR now contains two new things (feature flags and validation) but it didn't make sense to merge one without the other.

OFM Feature Branch: v3-labthings-validate-properties-on-set

@barecheck
Copy link

barecheck bot commented Mar 3, 2026

Barecheck - Code coverage report

Total: 96.38%

Your code coverage diff: 0.04% ▴

Uncovered files and lines
FileLines
src/labthings_fastapi/properties.py704, 708, 731-734, 806, 829, 1060

@rwb27 rwb27 added this to the v0.2.0 milestone Mar 3, 2026
@rwb27 rwb27 force-pushed the validate-properties-on-assignment branch from 5a37ae6 to 9f819fd Compare March 23, 2026 22:44
rwb27 added 3 commits March 25, 2026 12:18
This uses the existing validation logic in `PropertyInfo` to check assignments made in Python as well as set operations over HTTP.
I've added a module-level `FEATURE_FLAGS` object. This means validation of properties on set is disabled by default, but may be enabled if it's wanted.

The test suite checks both cases, and I've added a context manager to avoid accidental state leakage between tests.
@rwb27 rwb27 force-pushed the validate-properties-on-assignment branch from 9f819fd to 5fca4f1 Compare March 25, 2026 12:19
This makes sure we can't accidentally set flags that don't exist, which ought to help downstream code.
@rwb27 rwb27 force-pushed the validate-properties-on-assignment branch from e2d191f to 75b7388 Compare March 25, 2026 13:10
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