fix(backend): validate aspatial geopackage layer writes & add test co… - #1654
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughGeoPackage write-back now derives writable layers from geometry metadata and rejects aspatial-only targets with HTTP 400. Tests cover missing spatial layers and unrepairable degenerate geometries. ChangesVector validation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/geolibre_server/geolibre_server/app/vector.py`:
- Around line 232-236: Update the target-layer selection in _write_geopackage so
an omitted layer is resolved only from spatial layers; do not fall back to
names[0] when the GeoPackage contains only aspatial layers. Return the existing
“No feature layer to write” response for that case, and add a layer=None test
covering an aspatial-only GeoPackage.
In `@backend/geolibre_server/tests/test_vector_ops.py`:
- Around line 1206-1209: Add a second test case alongside the existing
mock_make_valid exception case that makes shapely.validation.make_valid return
an empty geometry. Exercise the empty-result repair path in the relevant vector
operation and assert that the original geometry is preserved and the unrepaired
count matches the exception case.
- Around line 1206-1207: Update mock_make_valid to annotate its return type as
NoReturn, rename the unused geom parameter to _geom, and raise ValueError
without the unnecessary inline message.
In `@backend/geolibre_server/tests/test_vector.py`:
- Around line 328-331: Update the mock_list_layers helper signature to annotate
its path parameter as unused and provide an explicit pandas DataFrame return
type, resolving Ruff ANN202 and ARG001 while preserving its existing DataFrame
result.
- Around line 335-338: Update the assertion following vector_write in the test
to compare exc.value.detail against the complete expected error message, rather
than checking only for the “aspatial table” substring; preserve the existing 400
status-code assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 481585cf-2f9d-48c1-b43d-18729b1b9146
📒 Files selected for processing (3)
backend/geolibre_server/geolibre_server/app/vector.pybackend/geolibre_server/tests/test_vector.pybackend/geolibre_server/tests/test_vector_ops.py
🔍 Cloudflare PR preview
|
|
/claude-review |
| raise HTTPException( | ||
| status_code=400, | ||
| detail=f"Layer '{layer}' is an aspatial table and cannot be written", | ||
| ) |
There was a problem hiding this comment.
Minor nit: the function's Raises docstring (a few lines up) still only says "The named layer is absent, or the file has several feature layers and none was specified" — worth extending it to mention this new aspatial-table 400 case so the docs stay in sync with the code. Not blocking.
Code reviewBugs: None found. The new Security: No issues found — no new input paths, injection surface, or secret handling introduced. Performance: No issues found — the fix reuses the already-computed Quality:
CLAUDE.md: No violations — this is a backend-only bugfix/test change with no dependency, lockfile, i18n, or menu-catalog impact, so none of the repo's special sync rules apply. Overall this is a small, well-targeted, low-risk fix with solid test coverage following existing patterns in the file. |
🔍 GitHub Pages PR preview
|
The explicit-layer guard rejected an aspatial table, but the auto-select path did not: with no layer specified, a GeoPackage whose only table is aspatial fell through to the `len(names) == 1` fallback and handed OGR the very table the guard above rejects, failing with a DataLayerError instead of a clean 400. That fallback is redundant for every other case (a single spatial layer is already covered by `spatial[0]`), so drop it and let the existing "No feature layer to write" response handle it. Also address review follow-ups: assert the full error detail, annotate the test mocks (Ruff ANN202/ARG001), cover both unfixable branches of _fix_geometries (make_valid raising vs returning empty), and extend the Raises: docstring to mention the aspatial-table 400.
|
Pushed b12ffbb addressing the review feedback — thanks @RohithPariki for catching the aspatial write path in the first place. The major one ( Verified rather than assumed: the new The rest:
Backend suite: 372 passed, 23 skipped. |
What
_write_geopackageaccepted any layer name that existed in the GeoPackage, including aspatial tables (those withgeometry_type = None). Passing an aspatial table name caused an OGR crash at write time instead of a clean HTTP errorWhy
The existing guard only checked
if layer not in names(404 for missing), but didnt check whether the matched layer was actually a spatial table.Fix
Add a second check
if layer not in spatialafter 404 guard, returning 400 with clear message:"Layer 'X' is an aspatial table and cannot be written".Tests
test_write_geopackage_rejects_aspatial_layer- verifies the new 400 pathtest_fix_geometries_leaves_unfixable_unchanged- covers the previously untestedunfixablebranch in_fix_geometries(geometry thatmake_validcant repair is left unchanged and counted)All 119 existing + new vector tests pass.
Summary by CodeRabbit