{"record":{"id":"afe22a9b024d979b","repo":"django/django","slug":"unable-to-handle-database-edition-database-type","errorCode":null,"errorMessage":"Unable to handle database edition: {database_type}","messagePattern":"Unable to handle database edition: (.+?)","errorType":"exception","errorClass":"GeoIP2Exception","httpStatus":null,"severity":"error","filePath":"django/contrib/gis/geoip2.py","lineNumber":120,"sourceCode":"                \"GeoIP path must be provided via parameter or the GEOIP_PATH setting.\"\n            )\n\n        path = to_path(path)\n\n        # Try the path first in case it is the full path to a database.\n        for path in (path, path / city, path / country):\n            if path.is_file():\n                self._path = path\n                self._reader = geoip2.database.Reader(path, mode=cache)\n                break\n        else:\n            raise GeoIP2Exception(\n                \"Path must be a valid database or directory containing databases.\"\n            )\n\n        database_type = self._metadata.database_type\n        if database_type not in SUPPORTED_DATABASE_TYPES:\n            raise GeoIP2Exception(f\"Unable to handle database edition: {database_type}\")\n\n    def __del__(self):\n        # Cleanup any GeoIP file handles lying around.\n        if self._reader:\n            self._reader.close()\n\n    def __repr__(self):\n        m = self._metadata\n        version = f\"v{m.binary_format_major_version}.{m.binary_format_minor_version}\"\n        return f\"<{self.__class__.__name__} [{version}] _path='{self._path}'>\"\n\n    @cached_property\n    def _metadata(self):\n        return self._reader.metadata()\n\n    @cached_property\n    def is_city(self):\n        return \"City\" in self._metadata.database_type","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/contrib/gis/geoip2.py#L102-L138","documentation":"Raised in GeoIP2.__init__ after opening the reader when the database's metadata.database_type is not in SUPPORTED_DATABASE_TYPES (GeoLite2-City, GeoLite2-Country, GeoIP2-City, GeoIP2-Country, DBIP-City-Lite, DBIP-Country-Lite). The wrapper only knows how to interpret City and Country editions; other MaxMind products (e.g. GeoIP2-Anonymous-IP, GeoIP2-ISP) are rejected.","triggerScenarios":"Opening a GeoIP2-ISP.mmdb, GeoIP2-Anonymous-IP.mmdb, GeoIP2-Domain.mmdb, GeoIP2-Connection-Type.mmdb, or any custom/enterprise mmdb whose database_type metadata string is not in the allowlist. Also triggered by a corrupt or placeholder mmdb whose metadata reports an unknown type.","commonSituations":"Subscribing to MaxMind insights and downloading the wrong product; bundling an enterprise mmdb; testing with a synthetic mmdb that has a non-standard database_type.","solutions":["Use a supported edition: GeoLite2/GeoIP2 City or Country, or DBIP-City-Lite/DBIP-Country-Lite","If you have an enterprise mmdb, use the geoip2 library directly (geoip2.database.Reader) instead of the Django wrapper","Verify the file: geoip2.database.Reader(path).metadata().database_type"],"exampleFix":"// before\nGeoIP2(path='/data/GeoIP2-ISP.mmdb')\n// after\nGeoIP2(path='/data/GeoLite2-City.mmdb')\n# or use maxmind directly for unsupported editions\nimport geoip2.database\nreader = geoip2.database.Reader('/data/GeoIP2-ISP.mmdb')","handlingStrategy":"validation","validationCode":"from django.contrib.gis.geoip2 import SUPPORTED_DATABASE_TYPES\nimport geoip2.database\n\ndef check_db_type(path):\n    db_type = geoip2.database.Reader(path).metadata().database_type\n    if db_type not in SUPPORTED_DATABASE_TYPES:\n        raise ValueError(f'Unsupported edition: {db_type}')\n    return db_type","typeGuard":"from django.contrib.gis.geoip2 import SUPPORTED_DATABASE_TYPES\nimport geoip2.database\n\ndef is_supported_db(path) -> bool:\n    return geoip2.database.Reader(path).metadata().database_type in SUPPORTED_DATABASE_TYPES","tryCatchPattern":"from django.contrib.gis.geoip2 import GeoIP2Exception\ntry:\n    g = GeoIP2(path=p)\nexcept GeoIP2Exception as e:\n    if 'database edition' in str(e):\n        # fall back to using geoip2.database.Reader directly\n        ...\n    raise","preventionTips":["Standardize on GeoLite2/GeoIP2 City or Country editions","For ISP/Anonymous-IP products use geoip2 directly","Validate mmdb metadata at deploy time"],"tags":["django-gis","geoip2","maxmind","database-edition","validation"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}