﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28981	django.contrib.gis.geoip2.GeoIP2 issue when GEOIP_PATH exists but there is no MaxMind database	Hugo Rodger-Brown	nobody	"When initialising a GeoIP2 object, if the GEOIP_PATH setting points to a directory that exists, but there is no MaxMind database in that location, the object is created in a state such that any call to `obj.__repr__` or `obj.info()` will raise an `AttributeError`.

**Expected behaviour:**

If it is possible to create a new GeoIP2 object in the absence of a source database, then the object methods should either handle that situation gracefully, or raise an appropriate error (e.g. `GeoIP2Exception`).

**Actual behaviour:**

If you create object and then call either `__repr__` (which can be done implicitly by calling `print(obj)`) or `info` methods, an `AttributeError` is raised.

{{{#!python
>>> from django.contrib.gis.geoip2 import GeoIP2
>>> g = GeoIP2()  # the GEOIP_PATH exists, but there is no database
>>> 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'
}}}

The problem is caused by both methods assuming that the `_reader` attribute will always be a valid `geoip2.database.Reader` object, which is **not** true in this case:

{{{#!python
>>> from django.contrib.gis.geoip2 import GeoIP2
>>> g = GeoIP2()  # the GEOIP_PATH exists, but there is no database
>>> assert g._city is None
>>> assert g._country is None
>>> assert g._reader is None
}}}
"	Uncategorized	new	GIS	1.11	Normal		geoip2 maxmind GEOIP_PATH		Unreviewed	0	0	0	0	0	0
