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

Better support for missing __name__ in frame traversal #58

Merged
merged 5 commits into from Sep 24, 2015

Conversation

Projects
None yet
3 participants
@Callek
Contributor

Callek commented Sep 15, 2015

In my own code, I got a new traceback for this issue (meant to be fixed in release of 15.1.0)

With some DEBUG prints sprinkled in, I was able to see that f.f_frame.has_key("__name__") was True, however f.f_frame.get("__name__", "?") would still return None thus skipping that default choice.

Per python docs, foo.get("whatever") already has a default value of None so simply mixing them with "or" will achieve the desired goal here in all existing cases, as well as fix my own case.

For reference the full traceback I had:

Traceback (most recent call last):
  File "/data/www/relengapi/celery", line 81, in <module>
    load_entry_point('celery', 'console_scripts', 'celery')()
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/celery/__main__.py", line 30, in main
    main()
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/celery/bin/celery.py", line 81, in main
    cmd.execute_from_commandline(argv)
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/celery/bin/celery.py", line 769, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/celery/bin/base.py", line 307, in execute_from_commandline
    return self.handle_argv(self.prog_name, argv[1:])
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/celery/bin/celery.py", line 761, in handle_argv
    return self.execute(command, argv)
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/celery/bin/celery.py", line 693, in execute
    ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/celery/bin/worker.py", line 179, in run_from_argv
    return self(*args, **options)
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/celery/bin/base.py", line 270, in __call__
    ret = self.run(*args, **kwargs)
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/celery/bin/worker.py", line 212, in run
    state_db=self.node_format(state_db, hostname), **kwargs
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/celery/worker/__init__.py", line 100, in __init__
    self.setup_instance(**self.prepare_args(**kwargs))
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/celery/worker/__init__.py", line 141, in setup_instance
    self.blueprint.apply(self, **kwargs)
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/celery/bootsteps.py", line 209, in apply
    self._debug('Preparing bootsteps.')
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/celery/bootsteps.py", line 272, in _debug
    return debug(_pre(self, msg), *args)
  File "/usr/lib/python2.7/logging/__init__.py", line 1128, in debug
    self._log(DEBUG, msg, args, **kwargs)
  File "/data/www/relengapi/celery", line 62, in new_log
    old_log(self, level, msg, args, exc_info=None, extra=extra)
  File "/usr/lib/python2.7/logging/__init__.py", line 1249, in _log
    fn, lno, func = self.findCaller()
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/structlog/stdlib.py", line 32, in findCaller
    f, name = _find_first_app_frame_and_name(['logging'])
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/structlog/_frames.py", line 41, in _find_first_app_frame_and_name
    while any(name.startswith(i) for i in ignores):
  File "/data/www/relengapi/virtualenv/lib/python2.7/site-packages/structlog/_frames.py", line 41, in <genexpr>
    while any(name.startswith(i) for i in ignores):
AttributeError: 'NoneType' object has no attribute 'startswith'

If this patch is accepted, I would appreciate a new structlog release, sooner than later.

@codecov-io

This comment has been minimized.

codecov-io commented Sep 15, 2015

Current coverage is 100.00%

Merging #58 into master will not affect coverage as of 78dc9c1

@@            master     #58   diff @@
======================================
  Files           12      12       
  Stmts          593     593       
  Branches        68      68       
  Methods          0       0       
======================================
  Hit            593     593       
  Partial          0       0       
  Missed           0       0       

Review entire Coverage Diff as of 78dc9c1

Powered by Codecov. Updated on successful CI builds.

@Callek

This comment has been minimized.

Contributor

Callek commented Sep 15, 2015

See-Also, Mozilla Bug 1192021 (comment # 11)

@hynek

This comment has been minimized.

Owner

hynek commented Sep 15, 2015

Nice edge case, thanks!

I can't release it before next week tho because I'm on a vacation and I don't have my notebook on me.

You can use the time to add yourself to authors. :)

@hynek

This comment has been minimized.

Owner

hynek commented Sep 15, 2015

Oh and please add a test case for your exact use case, thanks!

Fix one more spot of frame traversal, and write tests.
Also fixes _frame tests with "SyntaxWarning: assertion is always true, perhaps remove parentheses?"
And lastly add me to Authors.
@Callek

This comment has been minimized.

Contributor

Callek commented Sep 15, 2015

How's that?

@Callek

This comment has been minimized.

Contributor

Callek commented Sep 24, 2015

casual nudge. :-)

@hynek

This comment has been minimized.

Owner

hynek commented Sep 24, 2015

Sorry, first weeks are crazy. :)

@hynek

This comment has been minimized.

Owner

hynek commented Sep 24, 2015

Oops can you rebase/merge forward please?

@Callek

This comment has been minimized.

Contributor

Callek commented Sep 24, 2015

The conflict is from your py3.5 release notes change... but sure...

@Callek

This comment has been minimized.

Contributor

Callek commented Sep 24, 2015

...merged in master

hynek added a commit that referenced this pull request Sep 24, 2015

Merge pull request #58 from Callek/frame_traversal
Better support for missing __name__ in frame traversal

@hynek hynek merged commit b2ef5fe into hynek:master Sep 24, 2015

2 checks passed

codecov/project 100.00% (target 100.00%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@hynek

This comment has been minimized.

Owner

hynek commented Sep 25, 2015

FYI, 15.3.0 with this change is out. Thank you for your contribution: https://pypi.python.org/pypi/structlog/15.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment