From 38c7ccc6709a4e8b4fbe85f3494b9a278e299351 Mon Sep 17 00:00:00 2001 From: Matt Hammerly Date: Thu, 20 Jul 2023 09:06:47 -0700 Subject: [PATCH 1/2] rename cache _log_hits log args to avoid reserved names --- shared/helpers/cache.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shared/helpers/cache.py b/shared/helpers/cache.py index 6cda61d4..3708737b 100644 --- a/shared/helpers/cache.py +++ b/shared/helpers/cache.py @@ -88,7 +88,6 @@ def set(self, key: str, ttl: int, value: Any): class RedisBackend(BaseBackend): - current_protocol = pickle.DEFAULT_PROTOCOL def __init__(self, redis_connection: Redis): @@ -220,7 +219,9 @@ def _log_hits(self, func, args, kwargs, key) -> None: kwargs_to_log[lkey] = kwargs[lkey] log.info( "Returning cache hit", - extra=dict(func=func, args=args_to_log, kwargs=kwargs_to_log, key=key), + extra=dict( + func=func, fn_args=args_to_log, fn_kwargs=kwargs_to_log, key=key + ), ) def cache_synchronous_function(self, func: Callable) -> Callable: From cebe4cdcfed141b7f999390b2deb80a6ac53f73e Mon Sep 17 00:00:00 2001 From: Matt Hammerly Date: Thu, 20 Jul 2023 09:19:38 -0700 Subject: [PATCH 2/2] whoops, fix tests --- tests/unit/helpers/test_cache.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/unit/helpers/test_cache.py b/tests/unit/helpers/test_cache.py index 8c3f970d..2f71f08e 100644 --- a/tests/unit/helpers/test_cache.py +++ b/tests/unit/helpers/test_cache.py @@ -156,8 +156,8 @@ def test_simple_caching_fake_backend_with_params(self, mocker): assert args == ("Returning cache hit",) assert "extra" in kwargs extra_logged = kwargs["extra"] - extra_args = extra_logged["args"] - extra_kwargs = extra_logged["kwargs"] + extra_args = extra_logged["fn_args"] + extra_kwargs = extra_logged["fn_kwargs"] assert extra_args == ["base", "head"] assert extra_kwargs == { "something": "else" @@ -171,8 +171,8 @@ def test_simple_caching_fake_backend_with_params(self, mocker): assert args == ("Returning cache hit",) assert "extra" in kwargs extra_logged = kwargs["extra"] - extra_args = extra_logged["args"] - extra_kwargs = extra_logged["kwargs"] + extra_args = extra_logged["fn_args"] + extra_kwargs = extra_logged["fn_kwargs"] assert extra_args == ["base"] assert extra_kwargs == { "head": "head", @@ -216,8 +216,8 @@ async def test_simple_caching_fake_backend_async_with_params(self, mocker): assert args == ("Returning cache hit",) assert "extra" in kwargs extra_logged = kwargs["extra"] - extra_args = extra_logged["args"] - extra_kwargs = extra_logged["kwargs"] + extra_args = extra_logged["fn_args"] + extra_kwargs = extra_logged["fn_kwargs"] assert extra_args == ["base", "head"] assert extra_kwargs == { "something": "else" @@ -235,8 +235,8 @@ async def test_simple_caching_fake_backend_async_with_params(self, mocker): assert args == ("Returning cache hit",) assert "extra" in kwargs extra_logged = kwargs["extra"] - extra_args = extra_logged["args"] - extra_kwargs = extra_logged["kwargs"] + extra_args = extra_logged["fn_args"] + extra_kwargs = extra_logged["fn_kwargs"] assert extra_args == ["base"] assert extra_kwargs == { "head": "head",