{"action":"created","issue":{"url":"https://api.github.com/repos/omab/python-social-auth/issues/770","repository_url":"https://api.github.com/repos/omab/python-social-auth","labels_url":"https://api.github.com/repos/omab/python-social-auth/issues/770/labels{/name}","comments_url":"https://api.github.com/repos/omab/python-social-auth/issues/770/comments","events_url":"https://api.github.com/repos/omab/python-social-auth/issues/770/events","html_url":"https://github.com/omab/python-social-auth/pull/770","id":112688979,"number":770,"title":"Add atomic transaction around social_auth creation.","user":{"login":"doctoryes","id":7285237,"avatar_url":"https://avatars.githubusercontent.com/u/7285237?v=3","gravatar_id":"","url":"https://api.github.com/users/doctoryes","html_url":"https://github.com/doctoryes","followers_url":"https://api.github.com/users/doctoryes/followers","following_url":"https://api.github.com/users/doctoryes/following{/other_user}","gists_url":"https://api.github.com/users/doctoryes/gists{/gist_id}","starred_url":"https://api.github.com/users/doctoryes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doctoryes/subscriptions","organizations_url":"https://api.github.com/users/doctoryes/orgs","repos_url":"https://api.github.com/users/doctoryes/repos","events_url":"https://api.github.com/users/doctoryes/events{/privacy}","received_events_url":"https://api.github.com/users/doctoryes/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2015-10-21T22:05:29Z","updated_at":"2016-12-04T12:56:38Z","closed_at":"2016-12-04T12:56:38Z","pull_request":{"url":"https://api.github.com/repos/omab/python-social-auth/pulls/770","html_url":"https://github.com/omab/python-social-auth/pull/770","diff_url":"https://github.com/omab/python-social-auth/pull/770.diff","patch_url":"https://github.com/omab/python-social-auth/pull/770.patch"},"body":"Since Django 1.6, a `transaction.atomic` decorator has been available. There's a pattern that's supported in python_social_auth that performs a Django ORM operation and then handles a possible IntegrityError raised by the operation - see here:\n\nhttps://github.com/omab/python-social-auth/blob/master/social/pipeline/social_auth.py#L40\n\nThis pattern is even documented in the Django docs:\n\nhttps://docs.djangoproject.com/en/1.6/topics/db/transactions/#django.db.transaction.atomic\n\nHowever, if an IntegrityError is raised without being in a `transaction.atomic` block (via decorator or context manager), the transaction itself is left in a \"broken\" state - and any subsequent transaction operations will fail with the following exception:\n\n`An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.`\n\nThis condition is not detected in the current unittest suite because the IntegrityError scenario is tested by using a simple raise with no actual DB transaction:\n\nhttps://github.com/omab/python-social-auth/blob/aa66b83d4848c09defa57384529eca83597a3692/social/tests/test_pipeline.py#L21\n\nThis PR attempts to fix the broken transaction scenario. I've tested it with our https://github.com/edx/edx-platform test suite and it fixes the broken transaction. As a workaround for our Django 1.8 upgrade, I've monkey-patched edx-platform to fix the issue - that commit can be seen here:\n\nhttps://github.com/edx/edx-platform/commit/699ae371033869653a2ee79013a941f32b30e29c\n\nThe fix in this PR may not be the preferred one - but it does at least fix the issue. I'm happy to provide more information if needed.\n"},"comment":{"url":"https://api.github.com/repos/omab/python-social-auth/issues/comments/264702424","html_url":"https://github.com/omab/python-social-auth/pull/770#issuecomment-264702424","issue_url":"https://api.github.com/repos/omab/python-social-auth/issues/770","id":264702424,"user":{"login":"omab","id":91022,"avatar_url":"https://avatars.githubusercontent.com/u/91022?v=3","gravatar_id":"","url":"https://api.github.com/users/omab","html_url":"https://github.com/omab","followers_url":"https://api.github.com/users/omab/followers","following_url":"https://api.github.com/users/omab/following{/other_user}","gists_url":"https://api.github.com/users/omab/gists{/gist_id}","starred_url":"https://api.github.com/users/omab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omab/subscriptions","organizations_url":"https://api.github.com/users/omab/orgs","repos_url":"https://api.github.com/users/omab/repos","events_url":"https://api.github.com/users/omab/events{/privacy}","received_events_url":"https://api.github.com/users/omab/received_events","type":"User","site_admin":false},"created_at":"2016-12-04T12:56:38Z","updated_at":"2016-12-04T12:56:38Z","body":"Closing since this is already in the codebase https://github.com/python-social-auth/social-app-django/blob/master/social_django/storage.py#L112.\r\n\r\nThanks!"}}
{"actor":{"display_login":"omab"}}