Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.24.1: new _is_gis_field check throws exceptions when GDAL library not installed #821

Closed
glennmatthews opened this issue Sep 26, 2022 · 3 comments
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@glennmatthews
Copy link
Contributor

Describe the bug

After upgrading from drf-spectacular 0.24.0 to 0.24.1, with django 3.2 and django-filter 21.1, our users are reporting extremely slow schema generation and hundreds of new drf-spectacular warnings along the lines of:

?: (drf_spectacular.W001) AggregateViewSet: AggregateFilterSet: Unable to guess choice types from values, filter method's type hint or find "rir" in model. Defaulting to string.
?: (drf_spectacular.W001) AggregateViewSet: AggregateFilterSet: Unable to guess choice types from values, filter method's type hint or find "rir__n" in model. Defaulting to string.
?: (drf_spectacular.W001) AggregateViewSet: AggregateFilterSet: Unable to guess choice types from values, filter method's type hint or find "rir_id" in model. Defaulting to string.
?: (drf_spectacular.W001) AggregateViewSet: AggregateFilterSet: Unable to guess choice types from values, filter method's type hint or find "rir_id__n" in model. Defaulting to string.
?: (drf_spectacular.W001) AggregateViewSet: AggregateFilterSet: Unable to guess choice types from values, filter method's type hint or find "tag" in model. Defaulting to string.
?: (drf_spectacular.W001) AggregateViewSet: AggregateFilterSet: Unable to guess choice types from values, filter method's type hint or find "tag__n" in model. Defaulting to string.

I believe the culprit is the new _is_gis check added in 348a06e:

    def _is_gis(self, field):
        try:
            from django.contrib.gis.db.models import GeometryField
            from rest_framework_gis.filters import GeometryFilter

            return isinstance(field, (GeometryField, GeometryFilter))
        except ImportError:
            return False

In my environment, the above import does not raise an ImportError but instead raises a Django ImproperlyConfigured error:

>>> from django.contrib.gis.db.models import GeometryField
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
    import django.contrib.gis.db.models.functions  # NOQA
  File "/usr/local/lib/python3.7/site-packages/django/contrib/gis/db/models/functions.py", line 3, in <module>
    from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
  File "/usr/local/lib/python3.7/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
    from django.contrib.gis import forms, gdal
  File "/usr/local/lib/python3.7/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
    from .fields import (  # NOQA
  File "/usr/local/lib/python3.7/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module>
    from django.contrib.gis.gdal import GDALException
  File "/usr/local/lib/python3.7/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
    from django.contrib.gis.gdal.datasource import DataSource
  File "/usr/local/lib/python3.7/site-packages/django/contrib/gis/gdal/datasource.py", line 40, in <module>
    from django.contrib.gis.gdal.driver import Driver
  File "/usr/local/lib/python3.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 "/usr/local/lib/python3.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 "/usr/local/lib/python3.7/site-packages/django/contrib/gis/gdal/libgdal.py", line 49, in <module>
    % '", "'.join(lib_names)
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal3.2.0", "gdal3.1.0", "gdal3.0.0", "gdal2.4.0", "gdal2.3.0", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

To Reproduce

  1. Create a virtualenv and install django==3.2.15
  2. python -c "from django.contrib.gis.db.models import GeometryField"

Expected behavior

Lack of GIS support should not impact schema generation performance or functionality of non-GIS schema.

@tfranzel
Copy link
Owner

oh boy GIS is painful. #820 just got opened for this. fix will be coming asap.

tfranzel added a commit that referenced this issue Sep 26, 2022
tfranzel added a commit that referenced this issue Sep 26, 2022
@tfranzel tfranzel added bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending labels Sep 26, 2022
@tfranzel
Copy link
Owner

just released 0.24.2 with the bugfix. let me know if it works out. man, it is so easy to trip up with the GIS stuff.

@glennmatthews
Copy link
Contributor Author

Thanks for the super speedy fix!

tfranzel added a commit that referenced this issue Feb 25, 2023
 #775 #777

will coventiently make ``./runtests.py`` brush over system library
requirements to help contributors run the test suite locally without
installing extra stuff.

full tox run will require it though.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending
Projects
None yet
Development

No branches or pull requests

2 participants