Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/sentry/buffer/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _dump_values(cls, values: dict[Any, Any]) -> dict[Any, tuple[str, str]]:
@classmethod
def _dump_value(
cls,
value: str | datetime | date | int | float | dict[str, Any] | None,
value: str | datetime | date | int | float | dict[str, Any] | list[Any] | None,
depth: int = 0,
) -> tuple[str, str]:
if depth > 3:
Expand All @@ -297,14 +297,17 @@ def _dump_value(
elif isinstance(value, dict):
type_ = "di"
value = json.dumps({k: cls._dump_value(v, depth + 1) for k, v in value.items()})
elif isinstance(value, list):
type_ = "l"
value = json.dumps([cls._dump_value(item, depth + 1) for item in value])
else:
raise TypeError(type(value))
return type_, str(value)

@classmethod
def _load_values(
cls, payload: dict[str, tuple[str, Any]]
) -> dict[str, str | datetime | date | int | float | dict[str, Any] | None]:
) -> dict[str, str | datetime | date | int | float | dict[str, Any] | list[Any] | None]:
result = {}
for k, (t, v) in payload.items():
result[k] = cls._load_value((t, v))
Expand All @@ -313,7 +316,7 @@ def _load_values(
@classmethod
def _load_value(
cls, payload: tuple[str, Any]
) -> dict[str, Any] | str | datetime | date | int | float | None:
) -> dict[str, Any] | list[Any] | str | datetime | date | int | float | None:
(type_, value) = payload
if type_ == "n":
return None
Expand All @@ -332,6 +335,8 @@ def _load_value(
elif type_ == "di":
value = json.loads(value)
return {k: cls._load_value(v) for k, v in value.items()}
elif type_ == "l":
return [cls._load_value(item) for item in json.loads(value)]
else:
raise TypeError(f"invalid type: {type_}")

Expand Down
12 changes: 12 additions & 0 deletions tests/sentry/buffer/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,18 @@ def test_incr_uses_signal_only(self, default_group, task_runner) -> None:
(3.14, "float"),
({"a": {"i": 0}, "b": {"s": ""}}, "dict"),
(False, "bool"),
([1, "a", 3.14], "list"),
(
[
{
"parent_group_id": 4889213441,
"should_group": True,
"stacktrace_distance": 0.009,
"message_distance": 0.0,
}
],
"list_of_dicts",
),
],
ids=lambda input: input[1],
)
Expand Down
Loading