Opened 3 months ago

Closed 3 months ago

#35538 closed Bug (needsinfo)

GeometryFilter Causes GDALException

Reported by: Dustin Sampson Owned by: nobody
Component: GIS Version: 3.2
Severity: Normal Keywords:
Cc: Dustin Sampson Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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

Attachments (1)

gdal_exception.patch (593 bytes ) - added by Dustin Sampson 3 months ago.

Download all attachments as: .zip

Change History (2)

by Dustin Sampson, 3 months ago

Attachment: gdal_exception.patch added

comment:1 by Natalia Bidart, 3 months ago

Resolution: needsinfo
Status: newclosed

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?

Note: See TracTickets for help on using tickets.
Back to Top