Skip to content

Commit

Permalink
Deprecated django.contrib.gis.geoip2.GeoIP2.open().
Browse files Browse the repository at this point in the history
  • Loading branch information
ngnpope authored and felixxm committed Dec 5, 2023
1 parent 464af09 commit 07f9f99
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions django/contrib/gis/geoip2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,9 @@ def geos(self, query):

@classmethod
def open(cls, full_path, cache):
warnings.warn(
"GeoIP2.open() is deprecated. Use GeoIP2() instead.",
RemovedInDjango60Warning,
stacklevel=2,
)
return GeoIP2(full_path, cache)
2 changes: 2 additions & 0 deletions docs/internals/deprecation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ details on these changes.

* The ``django.contrib.gis.geoip2.GeoIP2.coords()`` method will be removed.

* The ``django.contrib.gis.geoip2.GeoIP2.open()`` method will be removed.

.. _deprecation-removed-in-5.1:

5.1
Expand Down
4 changes: 4 additions & 0 deletions docs/ref/contrib/gis/geoip2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ Instantiating
This classmethod instantiates the GeoIP object from the given database path
and given cache setting.

.. deprecated:: 5.1

Use the :class:`GeoIP2()` constructor instead.

Querying
--------

Expand Down
3 changes: 3 additions & 0 deletions docs/releases/5.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ Miscellaneous
* The ``django.contrib.gis.geoip2.GeoIP2.coords()`` method is deprecated. Use
``django.contrib.gis.geoip2.GeoIP2.lon_lat()`` instead.

* The ``django.contrib.gis.geoip2.GeoIP2.open()`` method is deprecated. Use the
:class:`~django.contrib.gis.geoip2.GeoIP2` constructor instead.

Features removed in 5.1
=======================

Expand Down
14 changes: 10 additions & 4 deletions tests/gis_tests/test_geoip2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ def test01_init(self):
g1 = GeoIP2() # Everything inferred from GeoIP path
path = settings.GEOIP_PATH
g2 = GeoIP2(path, 0) # Passing in data path explicitly.
g3 = GeoIP2.open(path, 0) # MaxMind Python API syntax.
# path accepts str and pathlib.Path.
if isinstance(path, str):
g4 = GeoIP2(pathlib.Path(path))
g3 = GeoIP2(pathlib.Path(path))
else:
g4 = GeoIP2(str(path))
g3 = GeoIP2(str(path))

for g in (g1, g2, g3, g4):
for g in (g1, g2, g3):
self.assertTrue(g._country)
self.assertTrue(g._city)

Expand Down Expand Up @@ -198,3 +197,10 @@ def test_coords_deprecation_warning(self):
e1, e2 = g.coords(self.fqdn)
self.assertIsInstance(e1, float)
self.assertIsInstance(e2, float)

def test_open_deprecation_warning(self):
msg = "GeoIP2.open() is deprecated. Use GeoIP2() instead."
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
g = GeoIP2.open(settings.GEOIP_PATH, 0)
self.assertTrue(g._country)
self.assertTrue(g._city)

0 comments on commit 07f9f99

Please sign in to comment.