Code repo: GSA/datagov-harvester
Problem
When a v3.0 spatial value is an array of Location objects, _unwrap_location() (general_utils.py:1250-1251) selects the first element that is truthy, not the first that is actually usable (i.e. has geometry/bbox/centroid):
if isinstance(input_value, list):
input_value = next((item for item in input_value if item), None)
A non-empty dict with only prefLabel is truthy, so it wins over a later element that actually carries geometry:
| Input |
Result |
[{bbox: POLYGON(…)}, {prefLabel: "Alaska"}] |
✅ Polygon |
[{prefLabel: "Alaska"}, {bbox: POLYGON(…)}] |
❌ NULL |
Order in the source feed silently determines whether a dataset gets a translated_spatial at all.
Separately (lower priority, same function): even when selection works, only one of N array elements is ever kept, so a multi-region spatial silently drops every region but the first. spatial_shape is a geo_shape OpenSearch field, so combining into a MultiPolygon/GeometryCollection is possible if that's wanted — that part is a product call, not filed as a fix here.
Suggested fix
In _unwrap_location, iterate the list and return the first element that actually unwraps to something usable (has a resolvable geometry/bbox/centroid, or is itself a bare GeoJSON dict), rather than the first truthy one.
Acceptance criteria
Context
Found in #6038 (SPIKE-3), finding 3.
Code repo: GSA/datagov-harvester
Problem
When a v3.0
spatialvalue is an array of Location objects,_unwrap_location()(general_utils.py:1250-1251) selects the first element that is truthy, not the first that is actually usable (i.e. hasgeometry/bbox/centroid):A non-empty dict with only
prefLabelis truthy, so it wins over a later element that actually carries geometry:[{bbox: POLYGON(…)}, {prefLabel: "Alaska"}][{prefLabel: "Alaska"}, {bbox: POLYGON(…)}]NULLOrder in the source feed silently determines whether a dataset gets a
translated_spatialat all.Separately (lower priority, same function): even when selection works, only one of N array elements is ever kept, so a multi-region
spatialsilently drops every region but the first.spatial_shapeis ageo_shapeOpenSearch field, so combining into aMultiPolygon/GeometryCollectionis possible if that's wanted — that part is a product call, not filed as a fix here.Suggested fix
In
_unwrap_location, iterate the list and return the first element that actually unwraps to something usable (has a resolvablegeometry/bbox/centroid, or is itself a bare GeoJSON dict), rather than the first truthy one.Acceptance criteria
[{no usable geometry}, {usable geometry}]resolves using the second element[{usable geometry}, {no usable geometry}]is unchanged (still resolves using the first)test_translate_spatial_location_array_uses_firststill passesContext
Found in #6038 (SPIKE-3), finding 3.