Fixed signature of views decorated with signed_data_view #1657
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a nuisance when using django-debug-toolbar with django-urlconfchecks which type checks URLconfs, and possibly other tools. Otherwise it has little effect.
Basically, the
@functools.wraps()
call within thesigned_data_view
decorator makes views likesql_explain
appear to have an external signature ofsql_explain(request, verified_data)
to tools like inspect.signature. If this was really the case, then the function would fail when used from the urlconf, because theverified_data
parameter is not passed.So, django-urlconfchecks raises an error for these views.
In reality
signed_data_view
is providing that argument, and so changing the effective signature of the function.With the patch, the signature is changed to
sql_explain(request, *args, **kwargs)
, which is not as accurate as it could be, but at least django-urlconfchecks now just issues a warning (about*args
/**kwargs
preventing signature checking), and not an error.An alternative fix is to remove the
@functools.wraps
call entirely in the implementation ofsigned_data_view
, but that would potentially produce more problems.A test is added for this.