Normalised both geom and point to 4326 in the containsPoint fn#1188
Normalised both geom and point to 4326 in the containsPoint fn#1188
Conversation
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/mobility-core/src/Kernel/Storage/Esqueleto/Functions.hs`:
- Around line 87-88: The containsPoint implementation currently uses setSRID
(ST_SetSRID(geom, 4326)) which only relabels metadata and can silently
misclassify coordinates; mirror the safer containsPointGeom pattern instead:
replace the unsafeSqlValue "geom" SRID relabeling with constructing the query
geometry explicitly (use ST_GeomFromText/POINT with lon/lat and SRID 4326 or
delegate to the containsPointGeom helper), updating the args construction and
any references to setSRID so the point is created with explicit SRID rather than
just relabeling the existing geom metadata.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: da16042f-9f48-433a-9cd6-97a43fcdb02e
📒 Files selected for processing (1)
lib/mobility-core/src/Kernel/Storage/Esqueleto/Functions.hs
| args = (setSRID (unsafeSqlValue "geom", val (4326 :: Int)), getPoint (val lat, val lon)) | ||
| setSRID = unsafeSqlFunction "ST_SetSRID" |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify whether geometry storage/usage guarantees 4326 coordinates.
set -euo pipefail
echo "1) Find geom column definitions and SRID constraints in migrations/schema files"
fd -HI . | xargs rg -n -C2 -P 'geom|geometry\(|geography\(|SRID|4326|AddGeometryColumn|ST_SetSRID|ST_Transform' || true
echo
echo "2) Find writes/builders of geom to detect source SRID assumptions"
rg -n -C2 -P 'ST_SetSRID\s*\(|ST_Transform\s*\(|ST_GeomFrom(Text|GeoJSON)\s*\(|ST_Point\s*\(' || true
echo
echo "3) Find all containsPoint implementations/callers for consistent CRS handling"
rg -n -C2 -P '\bcontainsPoint\b|\bst_contains\b' || trueRepository: nammayatri/shared-kernel
Length of output: 50381
Inconsistent SRID handling in containsPoint — consider containsPointGeom pattern
On Lines 87-88, ST_SetSRID(geom, 4326) only relabels SRID metadata; it does not reproject coordinates. While this works if geom is guaranteed to hold EPSG:4326 coordinates with missing metadata, the codebase has an alternative implementation containsPointGeom (lines 90–96) that constructs the point explicitly with SRID using ST_GeomFromText. For consistency and safety, either:
- Confirm via schema/migrations that
geomcolumn always stores 4326 coordinates and document this assumption, or - Use the
containsPointGeompattern throughout to avoid silent coordinate misclassification.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@lib/mobility-core/src/Kernel/Storage/Esqueleto/Functions.hs` around lines 87
- 88, The containsPoint implementation currently uses setSRID (ST_SetSRID(geom,
4326)) which only relabels metadata and can silently misclassify coordinates;
mirror the safer containsPointGeom pattern instead: replace the unsafeSqlValue
"geom" SRID relabeling with constructing the query geometry explicitly (use
ST_GeomFromText/POINT with lon/lat and SRID 4326 or delegate to the
containsPointGeom helper), updating the args construction and any references to
setSRID so the point is created with explicit SRID rather than just relabeling
the existing geom metadata.
Type of Change
Description
Normalised both geom and point to 4326 in the containsPoint fn
Additional Changes
Motivation and Context
How did you test it?
Checklist
./dev/format-all-files.shSummary by CodeRabbit