Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#27960 closed Bug (fixed)

ds = DataSource('/path/to/your/cities.shp') fails on first try (GDALException Unknown error code: "198770787"), but works on second

Reported by: Etiënne Thomassen Owned by: nobody
Component: GIS Version: 1.10
Severity: Normal Keywords: DataSource, GIS
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Etiënne Thomassen)

I can not create a DataSource from a gpx file. It returns GDALException Unknown error code: "198770787" with the error code number seemingly random. However on the second try it works. And it does not even need to be the same file.

Python 3.6.0 (default, Dec 24 2016, 08:01:42) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.contrib.gis.gdal import DataSource
>>> ds = DataSource('gpxfile1.gpx')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/etienne/.virtualenvs/venv1/lib/python3.6/site-packages/django/contrib/gis/gdal/datasource.py", line 64, in __init__
    Driver.ensure_registered()
  File "/Users/etienne/.virtualenvs/venv1/lib/python3.6/site-packages/django/contrib/gis/gdal/driver.py", line 83, in ensure_registered
    rcapi.register_all()
  File "/Users/etienne/.virtualenvs/venv1/lib/python3.6/site-packages/django/contrib/gis/gdal/prototypes/errcheck.py", line 119, in check_errcode
    check_err(result, cpl=cpl)
  File "/Users/etienne/.virtualenvs/venv1/lib/python3.6/site-packages/django/contrib/gis/gdal/error.py", line 74, in check_err
    raise GDALException('Unknown error code: "%s"' % code)
django.contrib.gis.gdal.error.GDALException: Unknown error code: "-1935278031"
>>> ds = DataSource('gpxfile2.gpx')
>>> ds.layer_count
5

This post on StackOverflow pointed me in this direction: http://stackoverflow.com/questions/41775536/datasource-gdalexception-unknown-error-code-474873798

Strangely, I can now get it to work doing this in my app:

try:
    datasource = DataSource(target_path)
except:
    datasource = DataSource(target_path)

Btw this part of my app stopped working migrating from Django 1.8 and Python 2.7 to Django 1.9 and Python 3.6. Now on Django 1.10 and Python 3.6

Attachments (1)

gpxfile.gpx (32.3 KB ) - added by Etiënne Thomassen 8 years ago.
Example gpx file (waypoints and tracks do not represent anything in real world). But any valid gpx file triggers the error

Download all attachments as: .zip

Change History (15)

comment:1 by Etiënne Thomassen, 8 years ago

Description: modified (diff)

comment:2 by Etiënne Thomassen, 8 years ago

Description: modified (diff)

comment:3 by Tim Graham, 8 years ago

Can you provide the gpx file in question? It would be helpful if you could bisect to find the Django commit where the behavior changed.

by Etiënne Thomassen, 8 years ago

Attachment: gpxfile.gpx added

Example gpx file (waypoints and tracks do not represent anything in real world). But any valid gpx file triggers the error

in reply to:  3 comment:4 by Etiënne Thomassen, 8 years ago

Replying to Tim Graham:

Can you provide the gpx file in question? It would be helpful if you could bisect to find the Django commit where the behavior changed.

Added an example gpx file that triggers the error. But any valid gpx file does so. Will look into bisect.

in reply to:  description ; comment:5 by Sergey Fedoseev, 8 years ago

Replying to Etiënne Thomassen:

I can't reproduce it. I tried both on master an on 1.10.

Could you try to replace

register_all = void_output(std_call('GDALAllRegister'), [])

with

register_all = void_output(std_call('GDALAllRegister'), [], errcheck=False)

in django/contrib/gis/gdal/prototypes/raster.py and say if it works for you?

Version 0, edited 8 years ago by Sergey Fedoseev (next)

comment:6 by Claude Paroz, 8 years ago

I think knowing the GDAL version on tested systems might be a key here.

in reply to:  6 comment:7 by Etiënne Thomassen, 8 years ago

Replying to Claude Paroz:

I think knowing the GDAL version on tested systems might be a key here.

I am using GDAL 2.1.2, released 2016/10/24 (with Django 1.10 and Python 3.6)

Previous version was 1.10.1 (with Django 1.8 and Python 2.7)

comment:8 by Claude Paroz, 8 years ago

I cannot reproduce but suspect the fix proposed by Sergei should work for you. Please try and report.

in reply to:  5 comment:9 by Etiënne Thomassen, 8 years ago

Replying to Sergey Fedoseev:

Replying to Etiënne Thomassen:

I can't reproduce it. I tried both on master and on 1.10.

Could you try to replace

register_all = void_output(std_call('GDALAllRegister'), [])

with

register_all = void_output(std_call('GDALAllRegister'), [], errcheck=False)

in django/contrib/gis/gdal/prototypes/raster.py and say if it works for you?

This works!

in reply to:  8 comment:10 by Etiënne Thomassen, 8 years ago

Replying to Claude Paroz:

I cannot reproduce but suspect the fix proposed by Sergei should work for you. Please try and report.

Thanks, I somehow missed Sergey's comment. He is right.

comment:11 by Sergey Fedoseev, 8 years ago

Has patch: set

comment:12 by Claude Paroz, 8 years ago

Triage Stage: UnreviewedReady for checkin

comment:13 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 7063a855:

Fixed #27960 -- Set errcheck=False for GDALAllRegister to prevent crash.

GDALAllRegister returns void so errcheck is not needed.

comment:14 by Tim Graham <timograham@…>, 8 years ago

In a937785e:

[1.11.x] Fixed #27960 -- Set errcheck=False for GDALAllRegister to prevent crash.

GDALAllRegister returns void so errcheck is not needed.

Backport of 7063a85579f40585f2601ba6e6887b0982e7ce43 from master

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