Opened 7 months ago

Closed 7 months ago

Last modified 7 months ago

#28178 closed Cleanup/optimization (fixed)

Allow applications that make optional use of contrib.gis to better silence the lack of a GDAL install

Reported by: Bas ten Berge Owned by: nobody
Component: GIS Version: 1.11
Severity: Release blocker Keywords: update 1.11.1
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I just updated Django 1.11 to 1.11.1 to learn my project would not start without changes to the settings. runserver stops with this message:

django.contrib.gis.gdal.error.GDALException: Could not find the GDAL library (tried "gdal", "GDAL", "gdal1.11.0", "gdal1.10.0", "gdal1.9.0", "gdal1.8.0", "gdal1.7.0"). Try setting GDAL_LIBRARY_PATH in your settings.

My installed apps:

...
DJANGO_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.humanize',
)

THIRD_PARTY_APPS = (
    'allauth',
    'mailer',
    'taggit',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
    'allauth.socialaccount.providers.linkedin_oauth2',
    'tastypie',
    'avatar',
    'reversion',
    'oauth2_provider',
    'channels',
    'compressor',
    'debug_toolbar', # django-debug-toolbar
)

BROWNPAPERSESSION_APPS = (
    'app',
    'invite',
    'apporg',
    'session', 
    'topic', 
)

INSTALLED_APPS = \
    DJANGO_APPS + THIRD_PARTY_APPS + BROWNPAPERSESSION_APPS

...

I could find a reference in the docs at https://docs.djangoproject.com/en/1.11/releases/1.11.1/:

Prevented hiding GDAL errors if it’s not installed when using contrib.gis (#28160). (It’s a required dependency as of Django 1.11.)

... but I didn't have the issue when I was running Django 1.11. I did not expect such a dependency change in a minor version update. How can I disable GIS?

Change History (9)

comment:1 Changed 7 months ago by Tim Graham

Can you please post the complete traceback so we can see what's importing django.contrib.gis?

comment:2 Changed 7 months ago by Bas ten Berge

Sure!

Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x5d38230>
Traceback (most recent call last):
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/channels/management/commands/runserver.py", line 47, in inner_run
    self.check(display_num_errors=True)
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/var/www/brownpapersession/dev/brownpapersession/brownpapersession/urls.py", line 16, in <module>
    from tastypie.api import Api, NamespacedApi
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/tastypie/api.py", line 11, in <module>
    from tastypie.resources import Resource
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/tastypie/resources.py", line 24, in <module>
    from django.contrib.gis.db.models.fields import GeometryField
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
    from django.contrib.gis.db.models.aggregates import *  # NOQA
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/contrib/gis/db/models/aggregates.py", line 1, in <module>
    from django.contrib.gis.db.models.fields import ExtentField
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
    from django.contrib.gis import forms, gdal
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
    from .fields import (  # NOQA
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/contrib/gis/forms/fields.py", line 4, in <module>
    from django.contrib.gis.geos import GEOSException, GEOSGeometry
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/contrib/gis/geos/__init__.py", line 5, in <module>
    from .collections import (  # NOQA
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/contrib/gis/geos/collections.py", line 11, in <module>
    from django.contrib.gis.geos.geometry import GEOSGeometry, LinearGeometryMixin
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/contrib/gis/geos/geometry.py", line 11, in <module>
    from django.contrib.gis import gdal
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
    from django.contrib.gis.gdal.datasource import DataSource
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/contrib/gis/gdal/datasource.py", line 39, in <module>
    from django.contrib.gis.gdal.driver import Driver
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
    from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
    from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
  File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/contrib/gis/gdal/libgdal.py", line 44, in <module>
    'GDAL_LIBRARY_PATH in your settings.' % '", "'.join(lib_names)
django.contrib.gis.gdal.error.GDALException: Could not find the GDAL library (tried "gdal", "GDAL", "gdal1.11.0", "gdal1.10.0", "gdal1.9.0", "gdal1.8.0", "gdal1.7.0"). Try setting GDAL_LIBRARY_PATH in your settings.
 

comment:3 Changed 7 months ago by Bas ten Berge

Looks like django-tastypie needs it, right?

comment:4 Changed 7 months ago by Tim Graham

Component: UncategorizedGIS
Severity: NormalRelease blocker
Summary: django.contrib.gis.gdal.error.GDALException after update to Django 1.11.1Allow applications that make optional use of contrib.gis to better silence the lack of a GDAL install
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

I would say that tastypie should catch GDALException, however, that exception isn't importable without GDAL installed! So, we might consider some change to Django to alleviate this -- perhaps ImproperlyConfigured could be raised here instead of GDALException.

comment:5 Changed 7 months ago by Claude Paroz

+1 to raise ImproperlyConfigured at this location.

comment:6 Changed 7 months ago by Bas ten Berge

Thanks for working on the issue and your time looking into the issue, as opposed to myself :flushed:

The name ImproperlyConfigured suggests the option is available as a configuration option. In my understanding, it's not possible to disable (or enable) gis via settings, as an individual setting. Right?

For anyone else looking into this issue: I changed the except statement on line 25 of tastypie/resources.py to get the project running on the Django 1.11.1:

except (ImproperlyConfigured, ImportError, Exception, ): # Exception is a workaround for GDALException

Could've just used Exception there...

comment:7 Changed 7 months ago by Tim Graham

Has patch: set

comment:8 Changed 7 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In c2975910:

Fixed #28178 -- Changed contrib.gis to raise ImproperlyConfigured if gdal isn't installed.

comment:9 Changed 7 months ago by Tim Graham <timograham@…>

In b3e56da0:

[1.11.x] Fixed #28178 -- Changed contrib.gis to raise ImproperlyConfigured if gdal isn't installed.

Backport of c2975910a5bc2729c2de01eb5b84777fa59551e1 from master

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