Skip to content

Commit 61254e0

Browse files
authored
Merge pull request #769 from felixxm/confirm-5.2
2 parents ed27999 + 036bb5d commit 61254e0

File tree

8 files changed

+43
-23
lines changed

8 files changed

+43
-23
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
- '4.2'
2323
- '5.0'
2424
- '5.1'
25+
- '5.2'
2526
redis-version:
2627
- 'latest'
2728

@@ -38,7 +39,7 @@ jobs:
3839
python-version: '3.9'
3940

4041
# latest Django with pre-release redis
41-
- django-version: '5.1'
42+
- django-version: '5.2'
4243
redis-version: 'master'
4344
python-version: '3.12'
4445

changelog.d/824.misc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Confirm support for Django 5.2.
2+
Fix shadowing builtin Python exceptions.

django_redis/client/default.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,21 @@
2121
from django.core.exceptions import ImproperlyConfigured
2222
from django.utils.module_loading import import_string
2323
from redis import Redis
24-
from redis.exceptions import ConnectionError, ResponseError, TimeoutError
24+
from redis.exceptions import ConnectionError as RedisConnectionError
25+
from redis.exceptions import ResponseError
26+
from redis.exceptions import TimeoutError as RedisTimeoutError
2527
from redis.typing import AbsExpiryT, EncodableT, ExpiryT, KeyT, PatternT
2628

2729
from django_redis import pool
2830
from django_redis.exceptions import CompressorError, ConnectionInterrupted
2931
from django_redis.util import CacheKey
3032

31-
_main_exceptions = (TimeoutError, ResponseError, ConnectionError, socket.timeout)
33+
_main_exceptions = (
34+
RedisConnectionError,
35+
RedisTimeoutError,
36+
ResponseError,
37+
socket.timeout,
38+
)
3239

3340
special_re = re.compile("([*?[])")
3441

@@ -1001,7 +1008,7 @@ def sscan(
10011008

10021009
cursor, result = client.sscan(
10031010
key,
1004-
match=cast(PatternT, self.encode(match)) if match else None,
1011+
match=cast("PatternT", self.encode(match)) if match else None,
10051012
count=count,
10061013
)
10071014
return {self.decode(value) for value in result}
@@ -1024,7 +1031,7 @@ def sscan_iter(
10241031
key = self.make_key(key, version=version)
10251032
for value in client.sscan_iter(
10261033
key,
1027-
match=cast(PatternT, self.encode(match)) if match else None,
1034+
match=cast("PatternT", self.encode(match)) if match else None,
10281035
count=count,
10291036
):
10301037
yield self.decode(value)

django_redis/client/herd.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44
from collections import OrderedDict
55

66
from django.conf import settings
7-
from redis.exceptions import ConnectionError, ResponseError, TimeoutError
7+
from redis.exceptions import ConnectionError as RedisConnectionError
8+
from redis.exceptions import ResponseError
9+
from redis.exceptions import TimeoutError as RedisTimeoutError
810

911
from django_redis.client.default import DEFAULT_TIMEOUT, DefaultClient
1012
from django_redis.exceptions import ConnectionInterrupted
1113

12-
_main_exceptions = (ConnectionError, ResponseError, TimeoutError, socket.timeout)
14+
_main_exceptions = (
15+
RedisConnectionError,
16+
RedisTimeoutError,
17+
ResponseError,
18+
socket.timeout,
19+
)
1320

1421

1522
class Marker:

django_redis/client/sharded.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Any, Iterator, List, Optional, Set, Union
55

66
from redis import Redis
7-
from redis.exceptions import ConnectionError
7+
from redis.exceptions import ConnectionError as RedisConnectionError
88
from redis.typing import KeyT
99

1010
from django_redis.client.default import DEFAULT_TIMEOUT, DefaultClient
@@ -130,7 +130,7 @@ def has_key(self, key, version=None, client=None):
130130
key = self.make_key(key, version=version)
131131
try:
132132
return client.exists(key) == 1
133-
except ConnectionError as e:
133+
except RedisConnectionError as e:
134134
raise ConnectionInterrupted(connection=client) from e
135135

136136
def delete(self, key, version=None, client=None):
@@ -256,7 +256,7 @@ def incr_version(self, key, delta=1, version=None, client=None):
256256

257257
try:
258258
ttl = self.ttl(old_key, version=version, client=client)
259-
except ConnectionError as e:
259+
except RedisConnectionError as e:
260260
raise ConnectionInterrupted(connection=client) from e
261261

262262
if value is None:
@@ -296,7 +296,7 @@ def keys(self, search, version=None):
296296
try:
297297
for connection in self._serverdict.values():
298298
keys.extend(connection.keys(pattern))
299-
except ConnectionError as e:
299+
except RedisConnectionError as e:
300300
# FIXME: technically all clients should be passed as `connection`.
301301
client = self.get_server(pattern)
302302
raise ConnectionInterrupted(connection=client) from e

setup.cfg

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ classifiers =
1515
Framework :: Django :: 4.2
1616
Framework :: Django :: 5.0
1717
Framework :: Django :: 5.1
18+
Framework :: Django :: 5.2
1819
Intended Audience :: Developers
1920
License :: OSI Approved :: BSD License
2021
Operating System :: OS Independent
@@ -59,10 +60,10 @@ envlist =
5960
mypy
6061
# tests against released versions
6162
py{38,39}-dj{42}-redislatest
62-
py{310,311,312}-dj{42,50,51}-redislatest
63+
py{310,311,312}-dj{42,50,51,52}-redislatest
6364
# tests against unreleased versions
64-
py311-dj51-redismaster
65-
py311-djmain-redis{latest,master}
65+
py312-dj52-redismaster
66+
py312-djmain-redis{latest,master}
6667

6768
[gh-actions]
6869
python =
@@ -77,6 +78,7 @@ DJANGO =
7778
4.2: dj42
7879
5.0: dj50
7980
5.1: dj51
81+
5.2: dj52
8082
main: djmain
8183
REDIS =
8284
latest: redislatest
@@ -91,6 +93,7 @@ deps =
9193
dj42: Django>=4.2,<5.0
9294
dj50: Django>=5.0,<5.1
9395
dj51: Django>=5.1,<5.2
96+
dj52: Django>=5.2,<6.0
9497
djmain: https://github.com/django/django/archive/main.tar.gz
9598
msgpack>=0.6.0
9699
pytest

tests/test_backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def test_delete_many_generator(self, cache: RedisCache):
300300
assert bool(res) is False
301301

302302
def test_delete_many_empty_generator(self, cache: RedisCache):
303-
res = cache.delete_many(key for key in cast(List[str], []))
303+
res = cache.delete_many(key for key in cast("List[str]", []))
304304
assert bool(res) is False
305305

306306
def test_incr(self, cache: RedisCache):
@@ -749,7 +749,7 @@ def test_primary_replica_switching(self, cache: RedisCache):
749749
if isinstance(cache.client, ShardClient):
750750
pytest.skip("ShardClient doesn't support get_client")
751751

752-
cache = cast(RedisCache, caches["sample"])
752+
cache = cast("RedisCache", caches["sample"])
753753
client = cache.client
754754
client._server = ["foo", "bar"]
755755
client._clients = ["Foo", "Bar"]
@@ -761,7 +761,7 @@ def test_primary_replica_switching_with_index(self, cache: RedisCache):
761761
if isinstance(cache.client, ShardClient):
762762
pytest.skip("ShardClient doesn't support get_client")
763763

764-
cache = cast(RedisCache, caches["sample"])
764+
cache = cast("RedisCache", caches["sample"])
765765
client = cache.client
766766
client._server = ["foo", "bar"]
767767
client._clients = ["Foo", "Bar"]

tests/test_cache_options.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55
from django.core.cache import caches
66
from pytest import LogCaptureFixture
7-
from redis.exceptions import ConnectionError
7+
from redis.exceptions import ConnectionError as RedisConnectionError
88

99
from django_redis.cache import RedisCache
1010
from django_redis.client import ShardClient
@@ -26,7 +26,7 @@ def ignore_exceptions_cache(settings) -> RedisCache:
2626
settings.CACHES = caches_setting
2727
settings.DJANGO_REDIS_IGNORE_EXCEPTIONS = True
2828
settings.DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS = True
29-
return cast(RedisCache, caches["doesnotexist"])
29+
return cast("RedisCache", caches["doesnotexist"])
3030

3131

3232
def test_get_django_omit_exceptions_many_returns_default_arg(
@@ -58,7 +58,7 @@ def test_get_django_omit_exceptions_priority_1(settings):
5858
caches_setting["doesnotexist"]["OPTIONS"]["IGNORE_EXCEPTIONS"] = True
5959
settings.CACHES = caches_setting
6060
settings.DJANGO_REDIS_IGNORE_EXCEPTIONS = False
61-
cache = cast(RedisCache, caches["doesnotexist"])
61+
cache = cast("RedisCache", caches["doesnotexist"])
6262
assert cache._ignore_exceptions is True
6363
assert cache.get("key") is None
6464

@@ -68,9 +68,9 @@ def test_get_django_omit_exceptions_priority_2(settings):
6868
caches_setting["doesnotexist"]["OPTIONS"]["IGNORE_EXCEPTIONS"] = False
6969
settings.CACHES = caches_setting
7070
settings.DJANGO_REDIS_IGNORE_EXCEPTIONS = True
71-
cache = cast(RedisCache, caches["doesnotexist"])
71+
cache = cast("RedisCache", caches["doesnotexist"])
7272
assert cache._ignore_exceptions is False
73-
with pytest.raises(ConnectionError):
73+
with pytest.raises(RedisConnectionError):
7474
cache.get("key")
7575

7676

@@ -84,7 +84,7 @@ def key_prefix_cache(cache: RedisCache, settings) -> Iterable[RedisCache]:
8484

8585
@pytest.fixture
8686
def with_prefix_cache() -> Iterable[RedisCache]:
87-
with_prefix = cast(RedisCache, caches["with_prefix"])
87+
with_prefix = cast("RedisCache", caches["with_prefix"])
8888
yield with_prefix
8989
with_prefix.clear()
9090

0 commit comments

Comments
 (0)