You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix write validation against empty transformations (#1118)
* Fix write validation not catching empty (rather than None) transformations
After remove_transformation(element, remove_all=True) the transformations
dict is set to {} rather than None, bypassing the is-None guard in all three
IO writers. Changed the check to `not transformations` so both None and empty
dicts are caught, and added a parametrized regression test covering images,
multiscale images, labels, multiscale labels, shapes, and points.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Move empty-transformation validation into model validate() methods
Instead of guarding in each IO writer, call get_model(element) (which
already dispatches to the right schema and runs validate()) at the start
of _write_element() for all non-table spatial elements.
Also fix the is-None guards in all three validate() methods to use
`not transformations` / `not data.attrs.get(key)` so that an empty
dict {} is caught in addition to None.
The IO-level guards added in the previous commit are removed since they
are now superseded by the model-level check; assert statements are kept
to narrow the type for mypy.
The regression test is updated to reflect the correct production scenario:
element is already inside a SpatialData object when its transformations are
removed in-place, so the error fires during write() not at construction.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Move empty-transformation validation into model validate() methods
Instead of guarding in each IO writer, call validate_element(element)
(a new public helper in spatialdata.models that delegates to get_model)
at the start of _write_element() for all non-table spatial elements.
Validation changes in models.py:
- RasterSchema._check_transforms_present: two explicit checks —
one for None (key absent) and one for empty dict, with separate messages
- ShapesModel.validate / PointsModel.validate: same split into two checks
- asserts in IO files are kept solely for mypy type-narrowing, each
annotated with a comment explaining that validate_element() guarantees
the invariant at runtime
New public API:
- spatialdata.models.validate_element(e) raises ValueError if the element
fails schema validation; documented in docs/api/models_utils.md
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
0 commit comments