Skip to content

ValueError: not enough values to unpack (expected 2, got 1) #1612

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
bblanchon opened this issue May 2, 2022 · 12 comments · Fixed by #1613
Closed

ValueError: not enough values to unpack (expected 2, got 1) #1612

bblanchon opened this issue May 2, 2022 · 12 comments · Fixed by #1613

Comments

@bblanchon
Copy link

Hi,

Thank you very much for this essential library ❤️

I just upgraded my project to Django 4.0.4 and now I frequently get the following exception when refreshing the page:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.9/site-packages/debug_toolbar/middleware.py", line 67, in __call__
    panel.generate_stats(request, response)
  File "/usr/local/lib/python3.9/site-packages/debug_toolbar/panels/sql/panel.py", line 230, in generate_stats
    query["stacktrace"] = render_stacktrace(query["stacktrace"])
  File "/usr/local/lib/python3.9/site-packages/debug_toolbar/utils.py", line 75, in render_stacktrace
    directory, filename = abspath.rsplit(os.path.sep, 1)
ValueError: not enough values to unpack (expected 2, got 1)

The value of abspath is '<frozen importlib._bootstrap>'.

Let me know if you need further information.

Best regards,
Benoit

@knyghty
Copy link

knyghty commented May 2, 2022

I'm getting the same kind of errors during tests after upgrading to 3.3.0, so the problem was likely introduced in this release.

@bblanchon
Copy link
Author

Indeed, I'm using django-debug-toolbar 3.3.0.

@matthiask
Copy link
Member

Thanks for the report! I'm unable to reproduce this (I tried with Python 3.9 and 3.10 in Linux/WSL)

Do you have a way to print the stack which fails, e.g. by printing the value of query["stacktrace"]? That may prove useful.

@knyghty
Copy link

knyghty commented May 2, 2022

It's a little hard to reproduce on my end. It only happens during tests (that I've noticed so far, anyway) and only when running pytest with xdist - so the tests running in parallel - and you can't use --pdb when running in parallel. Maybe that information is useful somehow.

@bblanchon
Copy link
Author

The exception occurs every time I hit refresh after a status code 500.

To reproduce:

  1. Edit a view to insert a bug (for example, an undefined symbol).
  2. Open the corresponding URL in your browser.
  3. Wait for the Django error page to show.
  4. Remove the bug from the view
  5. Refresh the page in the browser
  6. No error is expected, yet you can see "not enough values to unpack (expected 2, got 1)"

@tim-schilling
Copy link
Member

tim-schilling commented May 2, 2022

So what I think is happening is that render_stacktrace is being passed a list of frame data and expects the first frame element to be the path, but it's actually the frame.

@tim-schilling
Copy link
Member

@bblanchon could you get the other values for lineno, func, code, locals_ (remove sensitive data from locals_) for the iteration of the loop that causes the error?

@tim-schilling
Copy link
Member

@matthiask I don't think we're going to figure out what path and file to show when abspath is set to <frozen importlib._bootstrap>. This was probably always an issue but hidden by the Django template rendering system that was removed in #1571.

I think a reasonable solution would be:

if os.path.sep in abspath:
    directory, filename = abspath.rsplit(os.path.sep, 1)
else:
    directory = ""
    filename = abspath

I'm working on the PR to add the test to prevent regressions.

@tim-schilling
Copy link
Member

@bblanchon @knyghty could one of you confirm that #1613 fixes the issue for you locally?

@knyghty
Copy link

knyghty commented May 2, 2022

@tim-schilling yes, my tests are passing now with that patch at least.

@bblanchon
Copy link
Author

code = ''
func = '_find_andload'
lineno = 1007
locals_ = None

#1613 does fix the issue 👍

matthiask pushed a commit that referenced this issue May 2, 2022
Occassionally we will get a stacktrace that's an importlib instance string
representation. While we may be able to put the python path or something else
it's likely easier (and more logical) to simply pass that onto the user.

I was unable to reproduce the issue in our tests, so I've mocked the case
in test_importlib_path_issue_1612.

Fixes #1612
@tim-schilling
Copy link
Member

This fix was shipped in version 3.4 today.

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

Successfully merging a pull request may close this issue.

4 participants