Skip to content

GEOPY-2657: Allow UIJson forms to accept geoh5py.Entity#866

Open
domfournier wants to merge 3 commits intodevelopfrom
GEOPY-2657
Open

GEOPY-2657: Allow UIJson forms to accept geoh5py.Entity#866
domfournier wants to merge 3 commits intodevelopfrom
GEOPY-2657

Conversation

@domfournier
Copy link
Copy Markdown
Contributor

@domfournier domfournier commented Mar 27, 2026

GEOPY-2657 - Allow UIJson forms to accept geoh5py.Entity

Copilot AI review requested due to automatic review settings March 27, 2026 18:21
@github-actions github-actions bot changed the title GEOPY-2657 GEOPY-2657: Allow UIJson forms to accept geoh5py.Entity Mar 27, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_uuid validator to demote Entity inputs to their .uid.
  • Moved several Pydantic Annotated aliases (e.g., MeshTypes, GroupTypes, OptionalUUID*, PathList) into geoh5py/ui_json/annotations.py and updated imports accordingly.
  • Extended tests to cover passing ObjectForm.value as an entity and MultiSelectDataForm.value as 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):
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
if isinstance(value, list | tuple):
if isinstance(value, (list, tuple)):

Copilot uses AI. Check for mistakes.
Comment on lines +563 to +565
assert all(
data.uid == val for data, val in zip(data_list, form.value, strict=False)
)
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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))

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.22%. Comparing base (61d64e0) to head (e82db86).

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              
Files with missing lines Coverage Δ
geoh5py/ui_json/annotations.py 100.00% <100.00%> (ø)
geoh5py/ui_json/forms.py 95.03% <100.00%> (-0.16%) ⬇️
geoh5py/ui_json/validations/form.py 91.30% <100.00%> (+32.04%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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