Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
3a984d3c
Commit
3a984d3c
authored
Jun 22, 2016
by
Tasawer
Committed by
tasawernawaz
Jun 27, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make user enrollment more robust
ECOM-1730
parent
4f10552a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
42 deletions
+8
-42
common/djangoapps/student/models.py
+8
-26
common/djangoapps/student/tests/test_enrollment.py
+0
-16
No files found.
common/djangoapps/student/models.py
View file @
3a984d3c
...
...
@@ -1030,32 +1030,14 @@ class CourseEnrollment(models.Model):
if
user
.
id
is
None
:
user
.
save
()
try
:
enrollment
,
created
=
cls
.
objects
.
get_or_create
(
user
=
user
,
course_id
=
course_key
,
)
# If we *did* just create a new enrollment, set some defaults
if
created
:
enrollment
.
mode
=
CourseMode
.
DEFAULT_MODE_SLUG
enrollment
.
is_active
=
False
enrollment
.
save
()
except
IntegrityError
:
log
.
info
(
(
"An integrity error occurred while getting-or-creating the enrollment"
"for course key
%
s and student
%
s. This can occur if two processes try to get-or-create "
"the enrollment at the same time and the database is set to REPEATABLE READ. We will try "
"committing the transaction and retrying."
),
course_key
,
user
)
enrollment
=
cls
.
objects
.
get
(
user
=
user
,
course_id
=
course_key
,
)
enrollment
,
__
=
cls
.
objects
.
get_or_create
(
user
=
user
,
course_id
=
course_key
,
defaults
=
{
'mode'
:
CourseMode
.
DEFAULT_MODE_SLUG
,
'is_active'
:
False
}
)
return
enrollment
...
...
common/djangoapps/student/tests/test_enrollment.py
View file @
3a984d3c
...
...
@@ -8,7 +8,6 @@ from nose.plugins.attrib import attr
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
from
django.db
import
IntegrityError
from
course_modes.models
import
CourseMode
from
xmodule.modulestore.tests.django_utils
import
SharedModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
...
...
@@ -282,18 +281,3 @@ class EnrollmentTest(UrlResetMixin, SharedModuleStoreTestCase):
params
[
'email_opt_in'
]
=
email_opt_in
return
self
.
client
.
post
(
reverse
(
'change_enrollment'
),
params
)
def
test_get_or_create_integrity_error
(
self
):
"""Verify that get_or_create_enrollment handles IntegrityError."""
CourseEnrollmentFactory
.
create
(
user
=
self
.
user
,
course_id
=
self
.
course
.
id
)
with
patch
.
object
(
CourseEnrollment
.
objects
,
"get_or_create"
)
as
mock_get_or_create
:
mock_get_or_create
.
side_effect
=
IntegrityError
enrollment
=
CourseEnrollment
.
get_or_create_enrollment
(
self
.
user
,
self
.
course
.
id
)
self
.
assertEqual
(
enrollment
.
user
,
self
.
user
)
self
.
assertEqual
(
enrollment
.
course
.
id
,
self
.
course
.
id
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment