[Django] #31162: GIS error logging when using WKT string as input to filter() query

133 views
Skip to first unread message

Django

unread,
Jan 13, 2020, 4:35:12 AM1/13/20
to django-...@googlegroups.com
#31162: GIS error logging when using WKT string as input to filter() query
-----------------------------------------+------------------------
Reporter: Arno | Owner: nobody
Type: Uncategorized | Status: new
Component: GIS | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
When executing a geometry lookup like
`my_geo_model.objects.filter(my_geom__intersects=wkt_string)` (i.e. using
a WKT string as value) django.contrib.gis emits the following errors:

{{{
2020-01-13 10:16:07,145 - django.contrib.gis - ERROR - GDAL_ERROR 4:
b'POLYGON ((1 1, 1 0, 0 0, 0 1, 1 1)): No such file or directory'
2020-01-13 10:16:08,403 - django.contrib.gis - ERROR - GDAL_ERROR 10:
b"Pointer 'hObject' is NULL in 'GDALGetDescription'.\n"
}}}

The reason is that if passed a string, the string is first treated as a
potential filename which GDAL tries to open and fails ("no such file").
Only then it is tried to open the string as WKT/GeoJSON etc. Older Django
versions did not emit these errors. However, in commit 6f44f714c9 a check
in django/contrib/gis/gdal/raster/source.py:69 whether the file exists was
removed.

Silencing all errors from django.contrib.gis is not really a feasable
workaround, as it would mean silcencing interesting GIS errors too.

According to https://docs.djangoproject.com/en/2.2/ref/contrib/gis/db-api
/#geometry-lookups passing WKT strings is allowed, but there's no mention
of being able to pass a filename as parameter.

It's a bit unexpected that Django first tries to open a file before it
checks whether the passed string is valid WKT/GeoJSON, and that using WKT
results in error messages. Or am I misunderstanding the documentation and
calling the API wrongly?

Relevant parts of example source:

{{{
models.py:

class Area(models.Model):
area = models.PolygonField()

settings.py:

LOGGING = {
'version': 1,
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
},
},
'root': {
'handlers': ['console'],
'level': 'INFO',
}
}

main.py:

from app.models import Area
Area.objects.filter(area__intersects='POLYGON ((1 1, 1 0, 0 0, 0 1, 1
1))')
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31162>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 13, 2020, 6:34:31 AM1/13/20
to django-...@googlegroups.com
#31162: GIS error logging when using WKT string as input to filter() query.
------------------------+------------------------------------
Reporter: Arno | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+------------------------------------
Changes (by felixxm):

* type: Uncategorized => Bug
* version: 2.2 => master
* stage: Unreviewed => Accepted


Comment:

> According to https://docs.djangoproject.com/en/2.2/ref/contrib/gis/db-
api/#geometry-lookups passing WKT strings is allowed, but there's no


mention of being able to pass a filename as parameter.

Thanks for this report. Django tries to use a `GDALRaster` if you pass
`bytes` or `str` and if conversion is not successful then uses
`GEOSGeometry`.

`GDALRaster` accepts a string representing a file path. I agree that we
should restore
[https://github.com/django/django/commit/6f44f714c92d2966dca390ebd3054e5fb0bb0c80
#diff-6fa0bf748827a59b6730835b5439ded8L69-L70 the previous check] to avoid
logging:

{{{GDAL_ERROR 4: b'LINESTRING(0 0, 1 1, 5 5): No such file or
directory'}}}

We should also protect `GDALRaster._del__()` to avoid:

{{{GDAL_ERROR 10: b"Pointer 'hObject' is NULL in 'GDALGetDescription'.}}}

Maybe:
{{{
@cached_property
def is_vsi_based(self):
return self._ptr and
self.name.startswith(VSI_FILESYSTEM_BASE_PATH)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31162#comment:1>

Django

unread,
Jan 14, 2020, 4:39:58 PM1/14/20
to django-...@googlegroups.com
#31162: GIS error logging when using WKT string as input to filter() query.
------------------------+------------------------------------
Reporter: Arno | Owner: dbxnr
Type: Bug | Status: assigned

Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+------------------------------------
Changes (by dbxnr):

* owner: nobody => dbxnr
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/31162#comment:2>

Django

unread,
Jan 15, 2020, 10:42:16 PM1/15/20
to django-...@googlegroups.com
#31162: GIS error logging when using WKT string as input to filter() query.
------------------------+------------------------------------
Reporter: Arno | Owner: dbxnr
Type: Bug | Status: assigned
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+------------------------------------
Changes (by dbxnr):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/12327 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/31162#comment:3>

Django

unread,
Jan 15, 2020, 11:50:58 PM1/15/20
to django-...@googlegroups.com
#31162: GIS error logging when using WKT string as input to filter() query.
------------------------+------------------------------------
Reporter: Arno | Owner: (none)
Type: Bug | Status: new

Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+------------------------------------
Changes (by dbxnr):

* owner: dbxnr => (none)
* status: assigned => new
* has_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31162#comment:4>

Django

unread,
Jan 16, 2020, 1:42:34 AM1/16/20
to django-...@googlegroups.com
#31162: GIS error logging when using WKT string as input to filter() query.
------------------------+------------------------------------
Reporter: Arno | Owner: felixxm
Type: Bug | Status: assigned

Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+------------------------------------
Changes (by felixxm):

* owner: (none) => felixxm


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/31162#comment:5>

Django

unread,
Jan 16, 2020, 4:20:12 AM1/16/20
to django-...@googlegroups.com
#31162: GIS error logging when using WKT string as input to filter() query.
------------------------+------------------------------------
Reporter: Arno | Owner: felixxm
Type: Bug | Status: assigned
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+------------------------------------
Changes (by felixxm):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/12329 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/31162#comment:6>

Django

unread,
Jan 16, 2020, 8:35:05 AM1/16/20
to django-...@googlegroups.com
#31162: GIS error logging when using WKT string as input to filter() query.
------------------------+------------------------------------
Reporter: Arno | Owner: felixxm
Type: Bug | Status: closed
Component: GIS | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"266c853e10de50ce75af8be834647fda2c5fc2a0" 266c853e]:
{{{
#!CommitTicketReference repository=""
revision="266c853e10de50ce75af8be834647fda2c5fc2a0"
Fixed #31162 -- Prevented error logs when using WKT strings in lookups.

Thanks dbxnr for the initial patch.

Regression in 6f44f714c92d2966dca390ebd3054e5fb0bb0c80.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31162#comment:7>

Django

unread,
Aug 17, 2020, 6:13:20 AM8/17/20
to django-...@googlegroups.com
#31162: GIS error logging when using WKT string as input to filter() query.
------------------------+------------------------------------
Reporter: Arno | Owner: felixxm
Type: Bug | Status: closed
Component: GIS | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+------------------------------------

Comment (by John Chandler):

Is the fix scheduled for a Django 2.2 LTS release?

We have the same error being raised after upgrading to 2.2. The latest
2.2.15 release does not include the patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/31162#comment:8>

Django

unread,
Aug 17, 2020, 6:18:37 AM8/17/20
to django-...@googlegroups.com
#31162: GIS error logging when using WKT string as input to filter() query.
------------------------+------------------------------------
Reporter: Arno | Owner: felixxm
Type: Bug | Status: closed
Component: GIS | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+------------------------------------

Comment (by felixxm):

This patch will not be backported to Django 2.2. It's included in Django
3.1+.

--
Ticket URL: <https://code.djangoproject.com/ticket/31162#comment:9>

Reply all
Reply to author
Forward
0 new messages