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

Failing request with plain url produces excess backtraces #84

Open
ttolv opened this issue Nov 21, 2018 · 0 comments
Open

Failing request with plain url produces excess backtraces #84

ttolv opened this issue Nov 21, 2018 · 0 comments

Comments

@ttolv
Copy link

ttolv commented Nov 21, 2018

BaseTestCase.request allows e.g. self.get() with a named url, or a plain url as a fallback where the method is called within exception handling for reverse().

        try:
            self.last_response = method(reverse(url_name, args=args, kwargs=kwargs), data=data, follow=follow, **extra)
        except NoReverseMatch:
            self.last_response = method(url_name, data=data, follow=follow, **extra)

In the latter case, if the method fails, the exception chain will include less relevant traces:

Traceback (most recent call last):
  File "[...]/site-packages/django/urls/base.py", line 75, in reverse
    extra, resolver = resolver.namespace_dict[ns]
KeyError: 'https'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "[...]/site-packages/test_plus/test.py", line 133, in request
    self.last_response = method(reverse(url_name, args=args, kwargs=kwargs), data=data, follow=follow, **extra)
  File "[...]/site-packages/django/urls/base.py", line 86, in reverse
    raise NoReverseMatch("%s is not a registered namespace" % key)
django.urls.exceptions.NoReverseMatch: 'https' is not a registered namespace

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  [the actual test exception goes here]

Probably it would be preferable to call the method outside exception handling for reverse(), i.e.

        try:
            url = reverse(url_name, args=args, kwargs=kwargs)
        except NoReverseMatch:
            if args or kwargs:
                raise # unpopped (kw)args implies named url
            url = url_name
        self.last_response = method(url, data=data, follow=follow, **extra)

😃 No reverse()-related traces in failing tests when plain url used
😢 NoReverseMatch lost if invalid named url used without (kw)args, will barf only in fallback instead
🤔 Plain url with discarded (kw)args will barf non-backwards-compleniently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant