From 972ff5e4c3cc992a501d0e8d9cbec0923e207510 Mon Sep 17 00:00:00 2001 From: anthony sottile <103459774+asottile-sentry@users.noreply.github.com> Date: Wed, 24 Jul 2024 10:03:06 -0400 Subject: [PATCH] ref: match signatures in mocked bigtable implementation (#74805) fixes an error in mypy 1.11 --- src/sentry/utils/kvstore/abstract.py | 2 +- src/sentry/utils/kvstore/cache.py | 4 ++-- src/sentry/utils/kvstore/encoding.py | 2 +- src/sentry/utils/kvstore/memory.py | 2 +- src/sentry/utils/kvstore/redis.py | 2 +- .../sentry/nodestore/bigtable/test_backend.py | 22 ++++++++++++++----- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/sentry/utils/kvstore/abstract.py b/src/sentry/utils/kvstore/abstract.py index d5a84fa7df22b8..dd7da19b893b43 100644 --- a/src/sentry/utils/kvstore/abstract.py +++ b/src/sentry/utils/kvstore/abstract.py @@ -68,7 +68,7 @@ def delete_many(self, keys: Sequence[K]) -> None: self.delete(key) @abstractmethod - def bootstrap(self) -> None: + def bootstrap(self, automatic_expiry: bool = True) -> None: """ Allocate the resources (create tables, etc.) required by the store to be usable. diff --git a/src/sentry/utils/kvstore/cache.py b/src/sentry/utils/kvstore/cache.py index e52cc9578522d3..827e88e38d1a7e 100644 --- a/src/sentry/utils/kvstore/cache.py +++ b/src/sentry/utils/kvstore/cache.py @@ -38,7 +38,7 @@ def set(self, key: Any, value: Any, ttl: timedelta | None = None) -> None: def delete(self, key: Any) -> None: self.backend.delete(key) - def bootstrap(self) -> None: + def bootstrap(self, automatic_expiry: bool = True) -> None: # Nothing to do in this method: the backend is expected to either not # require any explicit setup action (memcached, Redis) or that setup is # assumed to be managed elsewhere (e.g. the Django database cache is @@ -98,7 +98,7 @@ def delete(self, key: str) -> None: def delete_many(self, keys: Sequence[str]) -> None: return self.storage.delete_many([wrap_key(self.prefix, self.version, key) for key in keys]) - def bootstrap(self) -> None: + def bootstrap(self, automatic_expiry: bool = True) -> None: self.storage.bootstrap() def destroy(self) -> None: diff --git a/src/sentry/utils/kvstore/encoding.py b/src/sentry/utils/kvstore/encoding.py index 189d040b56fd29..e697fed4a1866f 100644 --- a/src/sentry/utils/kvstore/encoding.py +++ b/src/sentry/utils/kvstore/encoding.py @@ -40,7 +40,7 @@ def delete(self, key: K) -> None: def delete_many(self, keys: Sequence[K]) -> None: return self.store.delete_many(keys) - def bootstrap(self) -> None: + def bootstrap(self, automatic_expiry: bool = True) -> None: return self.store.bootstrap() def destroy(self) -> None: diff --git a/src/sentry/utils/kvstore/memory.py b/src/sentry/utils/kvstore/memory.py index 748d3fdeb85630..c4c775aa99d3ec 100644 --- a/src/sentry/utils/kvstore/memory.py +++ b/src/sentry/utils/kvstore/memory.py @@ -42,7 +42,7 @@ def delete(self, key: K) -> None: except KeyError: pass - def bootstrap(self) -> None: + def bootstrap(self, automatic_expiry: bool = True) -> None: pass def destroy(self) -> None: diff --git a/src/sentry/utils/kvstore/redis.py b/src/sentry/utils/kvstore/redis.py index 3daab1115f0d15..b8e0ac3e1e4bc1 100644 --- a/src/sentry/utils/kvstore/redis.py +++ b/src/sentry/utils/kvstore/redis.py @@ -29,7 +29,7 @@ def set(self, key: str, value: T, ttl: timedelta | None = None) -> None: def delete(self, key: str) -> None: self.client.delete(key.encode("utf8")) - def bootstrap(self) -> None: + def bootstrap(self, automatic_expiry: bool = True) -> None: pass # nothing to do def destroy(self) -> None: diff --git a/tests/sentry/nodestore/bigtable/test_backend.py b/tests/sentry/nodestore/bigtable/test_backend.py index 5753bdd784a7de..3434face26aac9 100644 --- a/tests/sentry/nodestore/bigtable/test_backend.py +++ b/tests/sentry/nodestore/bigtable/test_backend.py @@ -46,14 +46,23 @@ def __init__(self): def direct_row(self, key): return MockedBigtableKVStorage.Row(self, key) - def read_row(self, key): - return MockedBigtableKVStorage.Row(self, key) - - def read_rows(self, row_set): + def read_row(self, row_key, filter_=None): + return MockedBigtableKVStorage.Row(self, row_key) + + def read_rows( + self, + start_key=None, + end_key=None, + limit=None, + filter_=None, + end_inclusive=False, + row_set=None, + retry=None, + ): assert not row_set.row_ranges, "unsupported" return [self.read_row(key) for key in row_set.row_keys] - def mutate_rows(self, rows): + def mutate_rows(self, rows, retry=None, timeout=None): # commits not implemented, changes are applied immediately return [Status(code=0) for row in rows] @@ -65,7 +74,7 @@ def _get_table(self, admin: bool = False): return table - def bootstrap(self, automatic_expiry): + def bootstrap(self, automatic_expiry: bool = True) -> None: pass @@ -98,6 +107,7 @@ def ns(request): yield MockedBigtableNodeStorage(project="test") +@pytest.mark.django_db def test_cache(ns): node_1 = ("a" * 32, {"foo": "a"}) node_2 = ("b" * 32, {"foo": "b"})