{"action":"created","issue":{"url":"https://api.github.com/repos/Pylons/pyramid_debugtoolbar/issues/319","repository_url":"https://api.github.com/repos/Pylons/pyramid_debugtoolbar","labels_url":"https://api.github.com/repos/Pylons/pyramid_debugtoolbar/issues/319/labels{/name}","comments_url":"https://api.github.com/repos/Pylons/pyramid_debugtoolbar/issues/319/comments","events_url":"https://api.github.com/repos/Pylons/pyramid_debugtoolbar/issues/319/events","html_url":"https://github.com/Pylons/pyramid_debugtoolbar/issues/319","id":239639464,"number":319,"title":"Logging issue on \"raise httpexceptions.HTTPFound(url)\"","user":{"login":"surabujin","id":2862761,"avatar_url":"https://avatars1.githubusercontent.com/u/2862761?v=3","gravatar_id":"","url":"https://api.github.com/users/surabujin","html_url":"https://github.com/surabujin","followers_url":"https://api.github.com/users/surabujin/followers","following_url":"https://api.github.com/users/surabujin/following{/other_user}","gists_url":"https://api.github.com/users/surabujin/gists{/gist_id}","starred_url":"https://api.github.com/users/surabujin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/surabujin/subscriptions","organizations_url":"https://api.github.com/users/surabujin/orgs","repos_url":"https://api.github.com/users/surabujin/repos","events_url":"https://api.github.com/users/surabujin/events{/privacy}","received_events_url":"https://api.github.com/users/surabujin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-06-29T23:35:04Z","updated_at":"2017-06-30T08:04:44Z","closed_at":null,"body":"Hi.\r\n\r\nIf view execute \"raise httpexceptions.HTTPFound(url)\" the traceback from logging module will appear in console (application started via pserve).\r\n\r\nTraceback:\r\n```\r\n--- Logging error ---\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python3.4/logging/__init__.py\", line 978, in emit\r\n    msg = self.format(record)\r\n  File \"/usr/lib/python3.4/logging/__init__.py\", line 828, in format\r\n    return fmt.format(record)\r\n  File \"/usr/lib/python3.4/logging/__init__.py\", line 573, in format\r\n    record.exc_text = self.formatException(record.exc_info)\r\n  File \"/usr/lib/python3.4/logging/__init__.py\", line 523, in formatException\r\n    traceback.print_exception(ei[0], ei[1], tb, None, sio)\r\n  File \"/usr/lib/python3.4/traceback.py\", line 169, in print_exception\r\n    for line in _format_exception_iter(etype, value, tb, limit, chain):\r\n  File \"/usr/lib/python3.4/traceback.py\", line 146, in _format_exception_iter\r\n    for value, tb in values:\r\n  File \"/usr/lib/python3.4/traceback.py\", line 125, in _iter_chain\r\n    context = exc.__context__\r\nAttributeError: 'NoneType' object has no attribute '__context__'\r\nCall stack:\r\n  File \"/usr/lib/python3.4/threading.py\", line 888, in _bootstrap\r\n    self._bootstrap_inner()\r\n  File \"/usr/lib/python3.4/threading.py\", line 920, in _bootstrap_inner\r\n    self.run()\r\n  File \"/usr/lib/python3.4/threading.py\", line 868, in run\r\n    self._target(*self._args, **self._kwargs)\r\n  File \"/srv/tenpho.com/lib/python3.4/site-packages/waitress-1.0.2-py3.4.egg/waitress/task.py\", line 78, in handler_thread\r\n    task.service()\r\n  File \"/srv/tenpho.com/lib/python3.4/site-packages/waitress-1.0.2-py3.4.egg/waitress/channel.py\", line 338, in service\r\n    task.service()\r\n  File \"/srv/tenpho.com/lib/python3.4/site-packages/waitress-1.0.2-py3.4.egg/waitress/task.py\", line 169, in service\r\n    self.execute()\r\n  File \"/srv/tenpho.com/lib/python3.4/site-packages/waitress-1.0.2-py3.4.egg/waitress/task.py\", line 399, in execute\r\n    app_iter = self.channel.server.application(env, start_response)\r\n  File \"/srv/tenpho.com/lib/python3.4/site-packages/pyramid-1.9-py3.4.egg/pyramid/router.py\", line 270, in __call__\r\n    response = self.execution_policy(environ, self)\r\n  File \"/srv/tenpho.com/lib/python3.4/site-packages/pyramid-1.9-py3.4.egg/pyramid/router.py\", line 276, in default_execution_policy\r\n    return router.invoke_request(request)\r\n  File \"/srv/tenpho.com/lib/python3.4/site-packages/pyramid-1.9-py3.4.egg/pyramid/router.py\", line 249, in invoke_request\r\n    response = handle_request(request)\r\n  File \"/home/tenpho/tenpho.com/repo/TenPho/tenpho/lib/web.py\", line 35, in __call__\r\n    return self.following(request)\r\n  File \"/srv/tenpho.com/lib/python3.4/site-packages/pyramid_debugtoolbar-4.2-py3.4.egg/pyramid_debugtoolbar/toolbar.py\", line 255, in toolbar_tween\r\n    _logger.exception(exc_msg, exc_info=request.exc_info)\r\nMessage: 'Squashed Exception at http://local.dev.tenpho.com:4080/fotografyi/change-pass\\ntraceback url: http://local.dev.tenpho.com:4080/_debug_toolbar/313430303634333836393034393736/exception'\r\nArguments: ()\r\n```\r\n\r\nLooks like issue lies in incorrect(at least for python3.4) call logging.exception. pyramid_debugtoolbar pass exc_info tuple into logging.exception method. \r\n```\r\n            response = _handler(request)\r\n            toolbar.status_int = response.status_int\r\n\r\n            if request.exc_info and intercept_exc:\r\n                toolbar.traceback = process_traceback(request.exc_info)\r\n\r\n                msg = 'Squashed Exception at %s\\ntraceback url: %s'\r\n                subrequest = make_subrequest(\r\n                    request, root_path, request.pdtb_id + '/exception')\r\n                exc_msg = msg % (request.url, subrequest.url)\r\n                _logger.exception(exc_msg, exc_info=request.exc_info)\r\n```\r\n\r\nBut if you take a look on this method:\r\n```\r\n1215 #---------------------------------------------------------------------------\r\n1216 #   Logger classes and functions\r\n1217 #---------------------------------------------------------------------------\r\n1218\r\n1219 class Logger(Filterer):\r\n\r\n# ...\r\n\r\n1305     def exception(self, msg, *args, **kwargs):\r\n1306         \"\"\"\r\n1307         Convenience method for logging an ERROR with exception information.\r\n1308         \"\"\"\r\n1309         kwargs['exc_info'] = True\r\n1310         self.error(msg, *args, **kwargs)\r\n```\r\nyou will see, that exc_info is replaces with \"True\".\r\n\r\nEnvironment:\r\n$ python --version\r\nPython 3.4.3\r\npyramid_debugtoolbar > 4.0.1\r\n\r\nPS Despite logging.exception issue - do we really need to catch/report raises of redirect exceptions?"},"comment":{"url":"https://api.github.com/repos/Pylons/pyramid_debugtoolbar/issues/comments/312203263","html_url":"https://github.com/Pylons/pyramid_debugtoolbar/issues/319#issuecomment-312203263","issue_url":"https://api.github.com/repos/Pylons/pyramid_debugtoolbar/issues/319","id":312203263,"user":{"login":"surabujin","id":2862761,"avatar_url":"https://avatars1.githubusercontent.com/u/2862761?v=3","gravatar_id":"","url":"https://api.github.com/users/surabujin","html_url":"https://github.com/surabujin","followers_url":"https://api.github.com/users/surabujin/followers","following_url":"https://api.github.com/users/surabujin/following{/other_user}","gists_url":"https://api.github.com/users/surabujin/gists{/gist_id}","starred_url":"https://api.github.com/users/surabujin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/surabujin/subscriptions","organizations_url":"https://api.github.com/users/surabujin/orgs","repos_url":"https://api.github.com/users/surabujin/repos","events_url":"https://api.github.com/users/surabujin/events{/privacy}","received_events_url":"https://api.github.com/users/surabujin/received_events","type":"User","site_admin":false},"created_at":"2017-06-30T08:04:44Z","updated_at":"2017-06-30T08:04:44Z","body":"\"We don't recommend raising HTTPFound\" who is \"we\" in this sentence?\r\n\r\nAccording to pyramid documentation HTTPFound can be returned from view or can be raised: https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/views.html#using-a-view-callable-to-do-an-http-redirect\r\n\r\nI prefer to raise exception objects, not return them... because they are exceptions (they are located in httpexceptions module). And I don't use pyramid_tm(I have my own transaction manager, capable to distinguish \"redirect\" exceptions and commit transaction if they are raised)."}}
{"actor":{"display_login":"surabujin"}}