Skip to content
Closed
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
6 changes: 2 additions & 4 deletions sentry_sdk/serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import math
from collections.abc import Mapping, Sequence, Set
from collections.abc import Mapping, Iterable
from datetime import datetime

from sentry_sdk.utils import (
Expand Down Expand Up @@ -331,9 +331,7 @@ def _serialize_node_impl(

return rv_dict

elif not isinstance(obj, serializable_str_types) and isinstance(
obj, (Set, Sequence)
):
elif not isinstance(obj, serializable_str_types) and isinstance(obj, Iterable):
rv_list = []

for i, v in enumerate(obj):
Expand Down
23 changes: 23 additions & 0 deletions tests/integrations/django/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
from werkzeug.test import Client

from django import VERSION as DJANGO_VERSION

from django.contrib.auth.models import User
from django.core.management import execute_from_command_line
from django.db.utils import OperationalError, ProgrammingError, DataError
from django.http.request import RawPostDataException
from django.utils.functional import SimpleLazyObject
from django.template.context import make_context

try:
from django.urls import reverse
Expand Down Expand Up @@ -310,6 +312,27 @@ def test_queryset_repr(sentry_init, capture_events):
)


@pytest.mark.forked
@pytest_mark_django_db_decorator()
def test_queryset_nested_repr(sentry_init, capture_events):
sentry_init(integrations=[DjangoIntegration()])
events = capture_events()
User.objects.create_user("john", "[email protected]", "johnpassword")

try:
context = make_context({"entries": User.objects.all()}) # noqa
1 / 0
except Exception:
capture_exception()

(event,) = events

(exception,) = event["exception"]["values"]
assert exception["type"] == "ZeroDivisionError"
(frame,) = exception["stacktrace"]["frames"]
assert "<User: " not in frame["vars"]["context"]


def test_custom_error_handler_request_context(sentry_init, client, capture_events):
sentry_init(integrations=[DjangoIntegration()])
events = capture_events()
Expand Down
12 changes: 12 additions & 0 deletions tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ def test_serialize_sets(extra_normalizer):
assert result == [1, 2, 3]


def test_serialize_custom_iter_class(extra_normalizer):
class MyList:
def __init__(self, list_):
self.list_ = list_

def __iter__(self):
return iter(self.list_)

result = extra_normalizer(MyList([1, 2, 3]))
assert result == [1, 2, 3]


def test_serialize_custom_mapping(extra_normalizer):
class CustomReprDict(dict):
def __sentry_repr__(self):
Expand Down
Loading