#28981: django.contrib.gis.geoip2.GeoIP2 issue when GEOIP_PATH exists but there 
is
no MaxMind database
-------------------------------------+-------------------------------------
               Reporter:  Hugo       |          Owner:  nobody
  Rodger-Brown                       |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:  GIS        |        Version:  1.11
               Severity:  Normal     |       Keywords:  geoip2 maxmind
           Triage Stage:             |  GEOIP_PATH
  Unreviewed                         |      Has patch:  0
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 If a GEOIP_PATH setting is specified, but there is no database file at
 that location, the initialisation of GeoIP2 runs without raising an error,
 which is the expected behaviour. However, during this process, neither the
 `_country` nor `_city` attributes are set (as there is no database), which
 means in turn that the `_reader` property will always return `None`. The
 problem occurs because both the `__repr__` and `info` methods expect the
 `_reader` to exist, and will fail with an `AttributeError` if it is None.

 The expected behaviour is that neither method will fail. The actual
 behaviour can be replicated below, where GEOIP_PATH is a valid directory
 that does not contain a MaxMind database file.

 {{{#!python
 >>> import os
 >>> from django.contrib.gis.geoip2 import GeoIP2
 >>> from django.contrib.gis.geoip2.base import GEOIP_SETTINGS
 >>> assert GEOIP_SETTINGS['GEOIP_PATH']
 >>> assert os.path.isdir(GEOIP_SETTINGS['GEOIP_PATH'])
 >>> g = GeoIP2()
 >>> assert g._city is None
 >>> assert g._country is None
 >>> assert g._reader is None
 >>> print(g)
 # traceback truncated
 ---> meta = self._reader.metadata()
 AttributeError: 'NoneType' object has no attribute 'metadata'
 >>> g.info()
 # traceback truncated
 ---> meta = self._reader.metadata()
 AttributeError: 'NoneType' object has no attribute 'metadata'
 }}}

 Error occurs in
 
`https://github.com/django/django/blob/1.11.9/django/contrib/gis/geoip2/base.py`

 Sugggested remedy: update `GeoIP2.__repr__` and `GeoIP2.info` to handle
 `_reader is None`.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/058.508922ac29ad010832c2303c64bfdcd1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to