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

NameError when referencing defined globals in the debugger. #913

Closed
justanr opened this issue Apr 26, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@justanr
Copy link

commented Apr 26, 2016

Running werkzeug .10.4 wrapped around Django via Django-Extensions to use the Don't Panic! debugger in dev environments. Version of Python is 2.7.8.

I'm running into an issue where I can't access variables defined in the session from lambdas or functions defined in the debugger. Example:

import os
map(lambda x: os.path.basename(x.name), bucket.list())

Causes a NameError: global name 'os' is not defined. The same happens if I define an actual function.

import os
def get_key_basename(key): return os.path.basename(key.name)
map(get_key_basename, bucket.list())

Happens with pretty much any variable in the debugger's scope.

I see the the code being passed to Don't Panic through the dev server (?__debugger__=yes&cmd=...). I can't recall ever hitting this behavior and some quick searching only reveals that a NameError issue was fixed back in .6.1 (no details provided in the changelog).

We are running with reloading, but no reloading happens between starting the debugger and the NameError occurring.

If I've simply missed something, feel free to close this. Otherwise, I'm happy to provide my information as needed.

@justanr justanr changed the title Naming scoping issues in debugger. NameError when referencing defined globals in the debugger. Apr 26, 2016

@untitaker

This comment has been minimized.

Copy link
Member

commented Apr 26, 2016

It would be helpful if you could reproduce this with barebones-Werkzeug and without any Django.

@justanr

This comment has been minimized.

Copy link
Author

commented Apr 28, 2016

Yeah, here's the simplest app that can reproduce.

from werkzeug.debug import DebuggedApplication
from werkzeug.serving import run_simple

def app(environ, start_response):
    raise Exception

if __name__ == '__main__':
    run_simple('localhost', 8000, DebuggedApplication(app, evalex=True))

Poking about some, it seems like debugger variables including imports get added to locals() and not globals(). For example:

# inside running debugged application
import os
(lambda: os)() # NameError
'os' in globals() # False
'os' in locals() # True
globals()['os'] = os
(lambda: os)() # <module 'os' ...>
'os' in globals() # True

Edit: This manifests in 2.7 and 3.5. I initially encountered it in Py 2.7, Werkzeug 0.10.4, but it manifests in 0.11.9 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.