pakal / django-compat-patcher

A system to improve compatibility between different Django versions, and make upgrading dependencies less painful.
MIT License
13 stars 2 forks source link

Django 1.x geos version check #18

Closed jayvdb closed 2 years ago

jayvdb commented 3 years ago

https://gist.github.com/jams2/11a60020a1ada897d79fc4c77fb587eb is about a defect in Django 1.11 preventing usage of GIS on newer distros, such as Ubuntu focus.

https://code.djangoproject.com/ticket/31838 is wontfix, but it looks like the fix is on the branch, unreleased. https://github.com/django/django/commit/a49764dd9daa11c4e24bad84423f71711b3e0de0

Patching the module after import doesnt work, because loading the module causes the version checker to be used, so chicken/egg problem.

   import django.contrib.gis.geos.libgeos as libgeos
  File "/home/travis/virtualenv/python3.8.3/lib/python3.8/site-packages/django/contrib/gis/geos/__init__.py", line 5, in <module>
    from .collections import (  # NOQA
  File "/home/travis/virtualenv/python3.8.3/lib/python3.8/site-packages/django/contrib/gis/geos/collections.py", line 11, in <module>
    from django.contrib.gis.geos.geometry import GEOSGeometry, LinearGeometryMixin
  File "/home/travis/virtualenv/python3.8.3/lib/python3.8/site-packages/django/contrib/gis/geos/geometry.py", line 20, in <module>
    from django.contrib.gis.geos.prototypes.io import (
  File "/home/travis/virtualenv/python3.8.3/lib/python3.8/site-packages/django/contrib/gis/geos/prototypes/io.py", line 215, in <module>
    class WKBWriter(IOBase):
  File "/home/travis/virtualenv/python3.8.3/lib/python3.8/site-packages/django/contrib/gis/geos/prototypes/io.py", line 219, in WKBWriter
    geos_version = geos_version_info()
  File "/home/travis/virtualenv/python3.8.3/lib/python3.8/site-packages/django/contrib/gis/geos/libgeos.py", line 196, in geos_version_info
    raise GEOSException('Could not parse version info string "%s"' % ver)
django.contrib.gis.geos.error.GEOSException: Could not parse version info string "3.8.0-CAPI-1.13.1 "

https://travis-ci.org/github/jayvdb/bluebottle/jobs/749482856 for the above backtrace.

It can be fixed by injecting the modified version_regex symbol during module loading. I dont recall whether compat-patcher-core has the ability to patch modules after loading yet before the module level code in them is executed. I do have a fairly advanced set of routines to do that, and it would be sensible to add it to CPC if it is missing.

pakal commented 3 years ago

At the moment DCP the underlying Compat-Patcher-Core have no utilities to edit module bytecode on import ; i don't kow how hard it is to do like Pytest and other "magic" modules.

However, since it's a very old version you're targetting, you could probably just vendor a fixed copy of libgeos.py (or one for py27 and one for py3K), and make this an optional fixer which only applies when specifically selected (like the optparse/argparse one). The fixer would inject this module in sys.modules at the right place, using compat-patcher-core utilities.

It might be necessary to also inject the name "libgeos" in django/contrib/gis/geos package, since the import system normally does that.

pakal commented 2 years ago

I'm closing this as it looks quite complicated, and Django 2&3 are the main retrocompatibility targets for DCP now ^^