Skip to content

Fixed signature of views decorated with signed_data_view #1657

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

Closed
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
4 changes: 4 additions & 0 deletions debug_toolbar/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ def inner(request, *args, **kwargs):
)
return HttpResponseBadRequest("Invalid signature")

# We have changed the signature, so need to remove `__wrapped__` to
# avoid confusing type checking tools
del inner.__wrapped__

return inner
21 changes: 21 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import inspect
import unittest

from django.test import override_settings

import debug_toolbar.utils
from debug_toolbar.decorators import signed_data_view
from debug_toolbar.utils import (
get_name_from_obj,
get_stack,
Expand Down Expand Up @@ -80,3 +82,22 @@ def test_deprecated_functions(self):
with self.assertWarns(DeprecationWarning):
stack_trace = tidy_stacktrace(reversed(stack))
self.assertEqual(stack_trace[-1][0], __file__)


class DecoratorsTestCase(unittest.TestCase):
def test_signed_data_view_signature(self):
# Ensure signed_data_view decorator sets an appropriate signature

# This matters only to tools that type-check the URLconf, (e.g.
# django-urlconfchecks), to avoid the nuisance of those tools flagging
# django-debug-toolbar views as incorrectly typed.

def some_view(request, verified_data):
pass

decorated_view = signed_data_view(some_view)

# `verified_data` is a parameter to some_view:
self.assertIn("verified_data", inspect.signature(some_view).parameters)
# but not to the decorated_view:
self.assertNotIn("verified_data", inspect.signature(decorated_view).parameters)