[Django] #35538: GeometryFilter Causes GDALException

9 views
Skip to first unread message

Django

unread,
Jun 19, 2024, 6:33:39 PM6/19/24
to django-...@googlegroups.com
#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.

Django

unread,
Jun 19, 2024, 6:34:50 PM6/19/24
to django-...@googlegroups.com
#35538: GeometryFilter Causes GDALException
--------------------------------+--------------------------------------
Reporter: Dustin Sampson | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Dustin Sampson):

* Attachment "gdal_exception.patch" added.

Django

unread,
Jun 19, 2024, 10:09:19 PM6/19/24
to django-...@googlegroups.com
#35538: GeometryFilter Causes GDALException
--------------------------------+--------------------------------------
Reporter: Dustin Sampson | Owner: nobody
Type: Bug | Status: closed
Component: GIS | Version: 3.2
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Natalia Bidart):

* resolution: => needsinfo
* status: new => closed

Comment:

Hello! Thank you for this report. Given that Django 3.2 is no longer
supported, could you please help us by checking if this issue exists in
the latest Django version?
--
Ticket URL: <https://code.djangoproject.com/ticket/35538#comment:1>
Reply all
Reply to author
Forward
0 new messages