{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/66788229","id":66788229,"diff_hunk":"@@ -1028,16 +1028,33 @@ def get_or_create_enrollment(cls, user, course_key):\n         if user.id is None:\n             user.save()\n \n-        enrollment, created = cls.objects.get_or_create(\n-            user=user,\n-            course_id=course_key,\n-        )\n+        try:\n+            enrollment, created = cls.objects.get_or_create(\n+                user=user,\n+                course_id=course_key,\n+            )\n \n-        # If we *did* just create a new enrollment, set some defaults\n-        if created:\n-            enrollment.mode = CourseMode.DEFAULT_MODE_SLUG\n-            enrollment.is_active = False\n-            enrollment.save()\n+            # If we *did* just create a new enrollment, set some defaults\n+            if created:\n+                enrollment.mode = CourseMode.DEFAULT_MODE_SLUG\n+                enrollment.is_active = False\n+                enrollment.save()\n+\n+        except IntegrityError:\n+            log.info(\n+                (\n+                    \"An integrity error occurred while getting-or-creating the enrollment\"\n+                    \"for course key %s and student %s. This can occur if two processes try to get-or-create \"\n+                    \"the enrollment at the same time and the database is set to REPEATABLE READ. We will try \"\n+                    \"committing the transaction and retrying.\"\n+                ),\n+                course_key, user\n+            )\n+            transaction.commit()","path":"common/djangoapps/student/models.py","position":35,"original_position":35,"commit_id":"5a7c79a6354d52d58a259985c8691e1d88c14548","original_commit_id":"5a7c79a6354d52d58a259985c8691e1d88c14548","user":{"login":"tasawernawaz","id":4245618,"avatar_url":"https://avatars.githubusercontent.com/u/4245618?v=3","gravatar_id":"","url":"https://api.github.com/users/tasawernawaz","html_url":"https://github.com/tasawernawaz","followers_url":"https://api.github.com/users/tasawernawaz/followers","following_url":"https://api.github.com/users/tasawernawaz/following{/other_user}","gists_url":"https://api.github.com/users/tasawernawaz/gists{/gist_id}","starred_url":"https://api.github.com/users/tasawernawaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tasawernawaz/subscriptions","organizations_url":"https://api.github.com/users/tasawernawaz/orgs","repos_url":"https://api.github.com/users/tasawernawaz/repos","events_url":"https://api.github.com/users/tasawernawaz/events{/privacy}","received_events_url":"https://api.github.com/users/tasawernawaz/received_events","type":"User","site_admin":false},"body":"@adampalay I think transaction is started but due to exception it did not committed.","created_at":"2016-06-13T13:10:19Z","updated_at":"2016-06-13T13:10:19Z","html_url":"https://github.com/edx/edx-platform/pull/12714#discussion_r66788229","pull_request_url":"https://api.github.com/repos/edx/edx-platform/pulls/12714","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/66788229"},"html":{"href":"https://github.com/edx/edx-platform/pull/12714#discussion_r66788229"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/12714"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/12714","id":73333188,"html_url":"https://github.com/edx/edx-platform/pull/12714","diff_url":"https://github.com/edx/edx-platform/pull/12714.diff","patch_url":"https://github.com/edx/edx-platform/pull/12714.patch","issue_url":"https://api.github.com/repos/edx/edx-platform/issues/12714","number":12714,"state":"open","locked":false,"title":"Fixed IntegrityError when making parallel enrollment requests for the same user / course","user":{"login":"tasawernawaz","id":4245618,"avatar_url":"https://avatars.githubusercontent.com/u/4245618?v=3","gravatar_id":"","url":"https://api.github.com/users/tasawernawaz","html_url":"https://github.com/tasawernawaz","followers_url":"https://api.github.com/users/tasawernawaz/followers","following_url":"https://api.github.com/users/tasawernawaz/following{/other_user}","gists_url":"https://api.github.com/users/tasawernawaz/gists{/gist_id}","starred_url":"https://api.github.com/users/tasawernawaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tasawernawaz/subscriptions","organizations_url":"https://api.github.com/users/tasawernawaz/orgs","repos_url":"https://api.github.com/users/tasawernawaz/repos","events_url":"https://api.github.com/users/tasawernawaz/events{/privacy}","received_events_url":"https://api.github.com/users/tasawernawaz/received_events","type":"User","site_admin":false},"body":"[ECOM-1730](https://openedx.atlassian.net/browse/ECOM-1730)\r\n\r\nUpdated method `get_or_create_enrollment` of model student for handling exception `IntegrityError` for concurrent enrollment requests from the same user.\r\n\r\nThis was previously fixed in [#9691](https://github.com/edx/edx-platform/pull/9691) but was probably mistakenly reverted in massive change [update Django to v1.8.5](https://github.com/edx/edx-platform/commit/6cb62f2697bcca1380854e139857678b2ddc35e0#diff-e2ffffdf6d67c9e0dee5bc10a67eb8bfL964) \r\n\r\nPlease review this @jareerahsan @ahsan-ul-haq @awais786 @waheedahmed ","created_at":"2016-06-10T07:44:32Z","updated_at":"2016-06-13T13:10:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aae8f1cdafbb111025e9738e929ba6e2987e8247","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-platform/pulls/12714/commits","review_comments_url":"https://api.github.com/repos/edx/edx-platform/pulls/12714/comments","review_comment_url":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-platform/issues/12714/comments","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/5a7c79a6354d52d58a259985c8691e1d88c14548","head":{"label":"edx:tasawer/bugfix/ecom-1730-fix-integrity-error-in-student-enrollment","ref":"tasawer/bugfix/ecom-1730-fix-integrity-error-in-student-enrollment","sha":"5a7c79a6354d52d58a259985c8691e1d88c14548","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"The Open edX platform, the software that powers edX!","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","deployments_url":"https://api.github.com/repos/edx/edx-platform/deployments","created_at":"2013-05-30T20:20:38Z","updated_at":"2016-06-13T08:07:22Z","pushed_at":"2016-06-13T12:36:35Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://open.edx.org/","size":768559,"stargazers_count":2618,"watchers_count":2618,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1593,"mirror_url":null,"open_issues_count":168,"forks":1593,"open_issues":168,"watchers":2618,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"f5b42c895521a5f7f864d573980974adc17d7d0b","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"The Open edX platform, the software that powers edX!","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","deployments_url":"https://api.github.com/repos/edx/edx-platform/deployments","created_at":"2013-05-30T20:20:38Z","updated_at":"2016-06-13T08:07:22Z","pushed_at":"2016-06-13T12:36:35Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://open.edx.org/","size":768559,"stargazers_count":2618,"watchers_count":2618,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1593,"mirror_url":null,"open_issues_count":168,"forks":1593,"open_issues":168,"watchers":2618,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/12714"},"html":{"href":"https://github.com/edx/edx-platform/pull/12714"},"issue":{"href":"https://api.github.com/repos/edx/edx-platform/issues/12714"},"comments":{"href":"https://api.github.com/repos/edx/edx-platform/issues/12714/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/12714/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/12714/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-platform/statuses/5a7c79a6354d52d58a259985c8691e1d88c14548"}}}}
{"actor":{"display_login":"tasawernawaz"}}