GEOPY-2657: Allow UIJson forms to accept geoh5py.Entity#866
GEOPY-2657: Allow UIJson forms to accept geoh5py.Entity#866domfournier wants to merge 3 commits intodevelopfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the UI JSON form validation/annotation layer so form fields that represent UUIDs can accept Entity instances (and lists of entities) and be automatically converted to UUIDs, with accompanying test updates.
Changes:
- Added an
entity_to_uuidvalidator to demoteEntityinputs to their.uid. - Moved several Pydantic
Annotatedaliases (e.g.,MeshTypes,GroupTypes,OptionalUUID*,PathList) intogeoh5py/ui_json/annotations.pyand updated imports accordingly. - Extended tests to cover passing
ObjectForm.valueas an entity andMultiSelectDataForm.valueas a list of data entities.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
tests/ui_json/forms_test.py |
Adds coverage for entity/list-of-entity inputs to form value fields. |
geoh5py/ui_json/validations/form.py |
Introduces entity_to_uuid and refactors UUID serialization helpers. |
geoh5py/ui_json/forms.py |
Switches form type aliases to centralized ui_json.annotations and keeps enums local. |
geoh5py/ui_json/annotations.py |
Centralizes shared Annotated aliases and wires in entity_to_uuid as a BeforeValidator. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def convert(value: UidOrNumeric) -> StringOrNumeric: | ||
| def entity_to_uuid(value: Any | list[Entity] | Entity) -> Any | list[UUID] | UUID: | ||
| """Demote an Entity to its UUID, and pass all other values.""" | ||
| if isinstance(value, list | tuple): |
There was a problem hiding this comment.
entity_to_uuid uses isinstance(value, list | tuple), but list | tuple is a union type and is not a valid second argument to isinstance (will raise TypeError at runtime). Use isinstance(value, (list, tuple)) (or a collections.abc.Sequence check) so list/tuple inputs are handled correctly.
| if isinstance(value, list | tuple): | |
| if isinstance(value, (list, tuple)): |
| assert all( | ||
| data.uid == val for data, val in zip(data_list, form.value, strict=False) | ||
| ) |
There was a problem hiding this comment.
This assertion can silently pass if form.value is missing items because zip(..., strict=False) truncates to the shorter input. Prefer zip(..., strict=True) (Python 3.10+) or explicitly assert the lengths match before comparing so the test fails on mismatched results.
| assert all( | |
| data.uid == val for data, val in zip(data_list, form.value, strict=False) | |
| ) | |
| assert len(data_list) == len(form.value) | |
| assert all(data.uid == val for data, val in zip(data_list, form.value)) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #866 +/- ##
===========================================
+ Coverage 91.14% 91.22% +0.08%
===========================================
Files 115 115
Lines 10332 10327 -5
Branches 1911 1910 -1
===========================================
+ Hits 9417 9421 +4
+ Misses 490 481 -9
Partials 425 425
🚀 New features to boost your workflow:
|
GEOPY-2657 - Allow UIJson forms to accept geoh5py.Entity