#35538: GeometryFilter Causes GDALException
------------------------------------------+------------------------
Reporter: Dustin Sampson | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
**Description**
When using a `GeometryFilter` in one of my `FilterSets`, passing a valid
GeoJSON `FeatureCollection` or an invalid JSON object (e.g., `{"a": 1}`)
results in a 500 error with the message `Invalid geometry pointer returned
from "OGR_G_CreateGeometryFromJson"` instead of a user-friendly "Invalid
geometry value" error.
**Steps to Reproduce**
1. Implement a `GeometryFilter` in a `FilterSet`.
2. Pass a valid GeoJSON `FeatureCollection` or an invalid JSON object
(`{"a": 1}`) to the filter.
3. Observe the 500 error with the message: `Invalid geometry pointer
returned from "OGR_G_CreateGeometryFromJson"`.
**Expected Behavior**
The system should raise a `ValidationError` with a user-friendly message,
such as "Invalid geometry value," instead of causing a 500 server error.
**Actual Behavior**
A 500 server error occurs with the message: `Invalid geometry pointer
returned from "OGR_G_CreateGeometryFromJson"`.
**Suggested Fix**
Modify the `to_python` method to include `GDALException` in the except
block when converting the value to a `GEOSGeometry`. This will catch the
exception and raise a `ValidationError` instead.
**Environment**
Django==3.2.20
djangorestframework-gis==1.0
djangorestframework==3.13.1
djangorestframework-gis==1.0
Python 3.10.14
GDAL 3.2.2, released 2021/03/05
--
Ticket URL: <https://code.djangoproject.com/ticket/35538>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107019032a23c76-5feb24bd-7c75-41c4-ad43-7285502769b1-000000%40eu-central-1.amazonses.com.