{"action":"created","issue":{"url":"https://api.github.com/repos/mitsuhiko/flask/issues/1563","labels_url":"https://api.github.com/repos/mitsuhiko/flask/issues/1563/labels{/name}","comments_url":"https://api.github.com/repos/mitsuhiko/flask/issues/1563/comments","events_url":"https://api.github.com/repos/mitsuhiko/flask/issues/1563/events","html_url":"https://github.com/mitsuhiko/flask/issues/1563","id":103379892,"number":1563,"title":"Flask g persisting across requests in test suite","user":{"login":"cmanallen","id":6018782,"avatar_url":"https://avatars.githubusercontent.com/u/6018782?v=3","gravatar_id":"","url":"https://api.github.com/users/cmanallen","html_url":"https://github.com/cmanallen","followers_url":"https://api.github.com/users/cmanallen/followers","following_url":"https://api.github.com/users/cmanallen/following{/other_user}","gists_url":"https://api.github.com/users/cmanallen/gists{/gist_id}","starred_url":"https://api.github.com/users/cmanallen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmanallen/subscriptions","organizations_url":"https://api.github.com/users/cmanallen/orgs","repos_url":"https://api.github.com/users/cmanallen/repos","events_url":"https://api.github.com/users/cmanallen/events{/privacy}","received_events_url":"https://api.github.com/users/cmanallen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-26T22:31:07Z","updated_at":"2015-08-26T22:33:37Z","closed_at":null,"body":"`g` seems to be persisting longer than it should.  My understanding is that `g` only exists during a request's context.  It shouldn't be persisted across multiple separate requests.\r\n\r\n**My auth handling**\r\nWhen you visit the resource a token is used to determine who you are.  Once we get the user_id from that token we persist it like the below code.\r\n\r\n```python\r\nif '_auth' not in g:\r\n    g._auth = Auth(user_id=user)\r\nreturn g._auth\r\n```\r\n\r\n**Test Setup**\r\n```python\r\ndef test(self):\r\n    get = self.client.get('users', headers=make_headers())\r\n    raise Exception(g._auth.user_id) # returns the user id outside the request context\r\n```\r\n\r\nAny ideas as to why `g` would be available?  Let me know if you need more information.  I wasn't sure how much to include."},"comment":{"url":"https://api.github.com/repos/mitsuhiko/flask/issues/comments/135196653","html_url":"https://github.com/mitsuhiko/flask/issues/1563#issuecomment-135196653","issue_url":"https://api.github.com/repos/mitsuhiko/flask/issues/1563","id":135196653,"user":{"login":"ThiefMaster","id":179599,"avatar_url":"https://avatars.githubusercontent.com/u/179599?v=3","gravatar_id":"","url":"https://api.github.com/users/ThiefMaster","html_url":"https://github.com/ThiefMaster","followers_url":"https://api.github.com/users/ThiefMaster/followers","following_url":"https://api.github.com/users/ThiefMaster/following{/other_user}","gists_url":"https://api.github.com/users/ThiefMaster/gists{/gist_id}","starred_url":"https://api.github.com/users/ThiefMaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThiefMaster/subscriptions","organizations_url":"https://api.github.com/users/ThiefMaster/orgs","repos_url":"https://api.github.com/users/ThiefMaster/repos","events_url":"https://api.github.com/users/ThiefMaster/events{/privacy}","received_events_url":"https://api.github.com/users/ThiefMaster/received_events","type":"User","site_admin":false},"created_at":"2015-08-26T22:33:37Z","updated_at":"2015-08-26T22:33:37Z","body":"It's stored on the app context. During a normal request both contexts have roughly the same lifetime."}}