Skip to content

Commit

Permalink
ref: match signatures in mocked bigtable implementation (#74805)
Browse files Browse the repository at this point in the history
fixes an error in mypy 1.11

<!-- Describe your PR here. -->
  • Loading branch information
asottile-sentry authored and Christinarlong committed Jul 26, 2024
1 parent 8cfe2c5 commit 972ff5e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/sentry/utils/kvstore/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/utils/kvstore/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/utils/kvstore/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/utils/kvstore/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/utils/kvstore/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 16 additions & 6 deletions tests/sentry/nodestore/bigtable/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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


Expand Down Expand Up @@ -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"})
Expand Down

0 comments on commit 972ff5e

Please sign in to comment.