Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sentr apps): Allow sentry app errors messages to take in kwargs #83142

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Christinarlong
Copy link
Contributor

Because of how we stringify an error in the current error handler we're lmited to only strings (i.e can't accept/stringify dictionaries) in the error messages which is limiting. This PR has the constructor for the error take in extras that we insert in the handler.

-->> Please give suggestions on how to do this better if possible ;-;

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 9, 2025
@Christinarlong Christinarlong marked this pull request as ready for review January 9, 2025 18:14
@Christinarlong Christinarlong requested review from a team as code owners January 9, 2025 18:14
Copy link

codecov bot commented Jan 9, 2025

❌ 17 Tests Failed:

Tests completed Failed Passed Skipped
23454 17 23437 271
View the top 3 failed tests by shortest run time
tests.sentry.sentry_apps.api.endpoints.test_sentry_apps.SuperuserStaffPostSentryAppsTest::test_superuser_read_cannot_create
Stack Traces | 1.69s run time
#x1B[1m#x1B[.../sentry/api/base.py#x1B[0m:419: in dispatch
    (args, kwargs) = self.convert_args(request, *args, **kwargs)
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:217: in convert_args
    self.check_object_permissions(request, context)
#x1B[1m#x1B[31m.venv/lib/python3.12.../site-packages/rest_framework/views.py#x1B[0m:345: in check_object_permissions
    if not permission.has_object_permission(request, self, obj):
#x1B[1m#x1B[.../sentry/api/permissions.py#x1B[0m:105: in has_object_permission
    if super().has_object_permission(request, *args, **kwargs):
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:106: in has_object_permission
    raise SentryAppIntegratorError(
#x1B[1m#x1B[31mE   sentry.sentry_apps.utils.errors.SentryAppIntegratorError: <exception str() failed>#x1B[0m

#x1B[33mDuring handling of the above exception, another exception occurred:#x1B[0m
#x1B[1m#x1B[.../api/endpoints/test_sentry_apps.py#x1B[0m:432: in test_superuser_read_cannot_create
    self.get_error_response(**self.get_data(name="POPULARITY"))
#x1B[1m#x1B[.../sentry/testutils/cases.py#x1B[0m:717: in get_error_response
    response = self.get_response(*args, **params)
#x1B[1m#x1B[.../sentry/testutils/cases.py#x1B[0m:665: in get_response
    return getattr(self.client, method)(url, format=format, data=data, **headers)
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:295: in post
    response = super().post(
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:209: in post
    return self.generic('POST', path, data, content_type, **extra)
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:233: in generic
    return super().generic(
#x1B[1m#x1B[31m.venv/lib/python3.12.../django/test/client.py#x1B[0m:676: in generic
    return self.request(**r)
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:285: in request
    return super().request(**kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:237: in request
    request = super().request(**kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../django/test/client.py#x1B[0m:1092: in request
    self.check_exception(response)
#x1B[1m#x1B[31m.venv/lib/python3.12.../django/test/client.py#x1B[0m:805: in check_exception
    raise exc_value
#x1B[1m#x1B[31m.venv/lib/python3.12.../core/handlers/exception.py#x1B[0m:55: in inner
    response = get_response(request)
#x1B[1m#x1B[31m.venv/lib/python3.12.../core/handlers/base.py#x1B[0m:197: in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../views/decorators/csrf.py#x1B[0m:65: in _view_wrapper
    return view_func(request, *args, **kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../views/generic/base.py#x1B[0m:104: in view
    return self.dispatch(request, *args, **kwargs)
#x1B[1m#x1B[.../sentry/silo/base.py#x1B[0m:158: in override
    return original_method(*args, **kwargs)
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:125: in dispatch
    return super().dispatch(request, *args, **kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../views/decorators/csrf.py#x1B[0m:65: in _view_wrapper
    return view_func(request, *args, **kwargs)
#x1B[1m#x1B[.../sentry/api/base.py#x1B[0m:119: in allow_cors_options_wrapper
    response = func(self, request, *args, **kwargs)
#x1B[1m#x1B[.../sentry/api/base.py#x1B[0m:438: in dispatch
    response = self.handle_exception_with_details(request, exc)
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:128: in handle_exception_with_details
    return self._handle_sentry_app_exception(
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:134: in _handle_sentry_app_exception
    response = Response({"detail": str(exception)}, status=exception.status_code)
#x1B[1m#x1B[.../sentry_apps/utils/errors.py#x1B[0m:26: in __str__
    if isinstance(Mapping, self.error.args[0]):
#x1B[1m#x1B[31mE   TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union#x1B[0m
tests.sentry.sentry_apps.api.endpoints.test_sentry_apps.SuperuserStaffPostSentryAppsTest::test_staff_cannot_create_app
Stack Traces | 1.75s run time
#x1B[1m#x1B[.../sentry/api/base.py#x1B[0m:419: in dispatch
    (args, kwargs) = self.convert_args(request, *args, **kwargs)
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:217: in convert_args
    self.check_object_permissions(request, context)
#x1B[1m#x1B[31m.venv/lib/python3.12.../site-packages/rest_framework/views.py#x1B[0m:345: in check_object_permissions
    if not permission.has_object_permission(request, self, obj):
#x1B[1m#x1B[.../sentry/api/permissions.py#x1B[0m:105: in has_object_permission
    if super().has_object_permission(request, *args, **kwargs):
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:106: in has_object_permission
    raise SentryAppIntegratorError(
#x1B[1m#x1B[31mE   sentry.sentry_apps.utils.errors.SentryAppIntegratorError: <exception str() failed>#x1B[0m

#x1B[33mDuring handling of the above exception, another exception occurred:#x1B[0m
#x1B[1m#x1B[.../api/endpoints/test_sentry_apps.py#x1B[0m:405: in test_staff_cannot_create_app
    response = self.get_error_response(**self.get_data(), status_code=400)
#x1B[1m#x1B[.../sentry/testutils/cases.py#x1B[0m:717: in get_error_response
    response = self.get_response(*args, **params)
#x1B[1m#x1B[.../sentry/testutils/cases.py#x1B[0m:665: in get_response
    return getattr(self.client, method)(url, format=format, data=data, **headers)
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:295: in post
    response = super().post(
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:209: in post
    return self.generic('POST', path, data, content_type, **extra)
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:233: in generic
    return super().generic(
#x1B[1m#x1B[31m.venv/lib/python3.12.../django/test/client.py#x1B[0m:676: in generic
    return self.request(**r)
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:285: in request
    return super().request(**kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:237: in request
    request = super().request(**kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../django/test/client.py#x1B[0m:1092: in request
    self.check_exception(response)
#x1B[1m#x1B[31m.venv/lib/python3.12.../django/test/client.py#x1B[0m:805: in check_exception
    raise exc_value
#x1B[1m#x1B[31m.venv/lib/python3.12.../core/handlers/exception.py#x1B[0m:55: in inner
    response = get_response(request)
#x1B[1m#x1B[31m.venv/lib/python3.12.../core/handlers/base.py#x1B[0m:197: in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../views/decorators/csrf.py#x1B[0m:65: in _view_wrapper
    return view_func(request, *args, **kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../views/generic/base.py#x1B[0m:104: in view
    return self.dispatch(request, *args, **kwargs)
#x1B[1m#x1B[.../sentry/silo/base.py#x1B[0m:158: in override
    return original_method(*args, **kwargs)
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:125: in dispatch
    return super().dispatch(request, *args, **kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../views/decorators/csrf.py#x1B[0m:65: in _view_wrapper
    return view_func(request, *args, **kwargs)
#x1B[1m#x1B[.../sentry/api/base.py#x1B[0m:119: in allow_cors_options_wrapper
    response = func(self, request, *args, **kwargs)
#x1B[1m#x1B[.../sentry/api/base.py#x1B[0m:438: in dispatch
    response = self.handle_exception_with_details(request, exc)
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:128: in handle_exception_with_details
    return self._handle_sentry_app_exception(
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:134: in _handle_sentry_app_exception
    response = Response({"detail": str(exception)}, status=exception.status_code)
#x1B[1m#x1B[.../sentry_apps/utils/errors.py#x1B[0m:26: in __str__
    if isinstance(Mapping, self.error.args[0]):
#x1B[1m#x1B[31mE   TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union#x1B[0m
tests.sentry.sentry_apps.api.endpoints.test_sentry_app_rotate_secret.SentryAppRotateSecretTest::test_invalid_app_id
Stack Traces | 2s run time
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:300: in convert_args
    sentry_app = SentryApp.objects.get(slug__id_or_slug=sentry_app_id_or_slug)
#x1B[1m#x1B[31m.venv/lib/python3.12.../db/models/manager.py#x1B[0m:87: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../db/models/query.py#x1B[0m:649: in get
    raise self.model.DoesNotExist(
#x1B[1m#x1B[31mE   sentry.sentry_apps.models.sentry_app.SentryApp.DoesNotExist: SentryApp matching query does not exist.#x1B[0m

#x1B[33mDuring handling of the above exception, another exception occurred:#x1B[0m
#x1B[1m#x1B[.../sentry/api/base.py#x1B[0m:419: in dispatch
    (args, kwargs) = self.convert_args(request, *args, **kwargs)
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:302: in convert_args
    raise SentryAppIntegratorError(
#x1B[1m#x1B[31mE   sentry.sentry_apps.utils.errors.SentryAppIntegratorError: <exception str() failed>#x1B[0m

#x1B[33mDuring handling of the above exception, another exception occurred:#x1B[0m
#x1B[1m#x1B[.../api/endpoints/test_sentry_app_rotate_secret.py#x1B[0m:53: in test_invalid_app_id
    response = self.client.post(path_with_invalid_id)
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:295: in post
    response = super().post(
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:209: in post
    return self.generic('POST', path, data, content_type, **extra)
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:233: in generic
    return super().generic(
#x1B[1m#x1B[31m.venv/lib/python3.12.../django/test/client.py#x1B[0m:676: in generic
    return self.request(**r)
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:285: in request
    return super().request(**kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.............../site-packages/rest_framework/test.py#x1B[0m:237: in request
    request = super().request(**kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../django/test/client.py#x1B[0m:1092: in request
    self.check_exception(response)
#x1B[1m#x1B[31m.venv/lib/python3.12.../django/test/client.py#x1B[0m:805: in check_exception
    raise exc_value
#x1B[1m#x1B[31m.venv/lib/python3.12.../core/handlers/exception.py#x1B[0m:55: in inner
    response = get_response(request)
#x1B[1m#x1B[31m.venv/lib/python3.12.../core/handlers/base.py#x1B[0m:197: in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../views/decorators/csrf.py#x1B[0m:65: in _view_wrapper
    return view_func(request, *args, **kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../views/generic/base.py#x1B[0m:104: in view
    return self.dispatch(request, *args, **kwargs)
#x1B[1m#x1B[.../sentry/silo/base.py#x1B[0m:158: in override
    return original_method(*args, **kwargs)
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:125: in dispatch
    return super().dispatch(request, *args, **kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../views/decorators/csrf.py#x1B[0m:65: in _view_wrapper
    return view_func(request, *args, **kwargs)
#x1B[1m#x1B[.../sentry/api/base.py#x1B[0m:119: in allow_cors_options_wrapper
    response = func(self, request, *args, **kwargs)
#x1B[1m#x1B[.../sentry/api/base.py#x1B[0m:438: in dispatch
    response = self.handle_exception_with_details(request, exc)
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:128: in handle_exception_with_details
    return self._handle_sentry_app_exception(
#x1B[1m#x1B[.../api/bases/sentryapps.py#x1B[0m:134: in _handle_sentry_app_exception
    response = Response({"detail": str(exception)}, status=exception.status_code)
#x1B[1m#x1B[.../sentry_apps/utils/errors.py#x1B[0m:26: in __str__
    if isinstance(Mapping, self.error.args[0]):
#x1B[1m#x1B[31mE   TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant