Skip to content

Fix leaflux/fosberg test fixtures writing grid bands without index - #549

Merged
amarcozzi merged 1 commit into
mainfrom
fix-grid-fixture-bands-missing-index
Aug 26, 2026
Merged

Fix leaflux/fosberg test fixtures writing grid bands without index#549
amarcozzi merged 1 commit into
mainfrom
fix-grid-fixture-bands-missing-index

Conversation

@amarcozzi

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #548. The post-deploy CI test job on main went red on 4 TestListGridsWildcard::test_wildcard_sorting_matrix_returns_200 cases (assert 500 == 200) — not a product regression; the deploy itself succeeded and the feature is live.

Root cause

The leaflux and fosberg router-test grid_factory fixtures write source-grid documents straight to Firestore with bands shaped [{"key": key}]missing the required index and type fields on Band.

CI runs the suite under pytest-xdist, and all tests share one test owner. While a leaflux/fosberg fixture grid is briefly alive on one worker, TestListGridsWildcard on another worker calls list_grids_cross_domain, which serializes every one of the owner's grids via Grid(**doc.to_dict()) (router.py:228) with no error handling. A fixture band with no index raises a Pydantic ValidationError → the endpoint returns 500 → the wildcard test fails.

Confirmed from prod logs: the failing input_values are exactly these fixtures ({'key': 'leaf_area_density'}, {'key': 'elevation'}, georef {'crs': 'EPSG:32611', 'shape': [6, 40, 40]}). The errors appeared only during the test session and stopped when the fixtures were torn down — the endpoint is healthy, and real API-created grids always have valid bands (this shape is only reachable by fixtures writing to Firestore directly).

Fix

Build the fixtures' bands with an enumerated index and type: "continuous" (every band these fixtures use — leaf_area_density, elevation, slope, aspect, irradiance.* — is continuous), so a concurrent cross-domain list serializes them cleanly:

data["bands"] = [
    {"key": key, "type": "continuous", "index": i}
    for i, key in enumerate(bands)
]

No product code changed. I deliberately left the list router alone — real data can't produce a bandless-index grid, so the fault is the fixtures, not the endpoint.

Verification

Ran leaflux + fosberg router tests and TestListGridsWildcard against a live server — 81 passed serially and 81 passed under 4-worker xdist (the parallel mode that triggered the flake). ruff check / format --check clean. Swept the suite for other fixtures with the same bandless-index pattern — none remain.

…an serialize them

The leaflux and fosberg router-test `grid_factory` fixtures wrote source-grid
documents straight to Firestore with bands shaped `{"key": key}` — missing the
required `index` and `type` fields. Under pytest-xdist these fixtures are
briefly alive in the shared test owner's collection while, on another worker,
`TestListGridsWildcard` calls `list_grids_cross_domain`, which does
`Grid(**doc.to_dict())` over every one of the owner's grids with no error
handling. Serializing a fixture band with no `index` raised a Pydantic
ValidationError, so the wildcard-list endpoint returned 500 and the test failed
(assert 500 == 200).

The failure was flaky/latent before but became a consistent post-deploy CI
failure once more fixture grids were added. Build the fixtures' bands with an
enumerated `index` and `type: continuous` (every band these fixtures use is
continuous), so a concurrent cross-domain list serializes them cleanly.

Test-only; no product change. Verified against a live server serially and under
4-worker xdist (the parallel mode that triggered the flake).
@amarcozzi
amarcozzi merged commit c26fa52 into main Aug 26, 2026
1 check passed
@amarcozzi
amarcozzi deleted the fix-grid-fixture-bands-missing-index branch August 26, 2026 21:28
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