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
02d4606e
Commit
02d4606e
authored
Sep 10, 2015
by
Tasawer
Committed by
Tasawer Nawaz
Sep 10, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing IntegrityError happened on concurrent requests for course enrollment
ECOM-1730
parent
1c910cfb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
10 deletions
+26
-10
common/djangoapps/student/models.py
+26
-10
No files found.
common/djangoapps/student/models.py
View file @
02d4606e
...
...
@@ -29,7 +29,7 @@ from django.utils import timezone
from
django.contrib.auth.models
import
User
from
django.contrib.auth.hashers
import
make_password
from
django.contrib.auth.signals
import
user_logged_in
,
user_logged_out
from
django.db
import
models
,
IntegrityError
from
django.db
import
models
,
IntegrityError
,
transaction
from
django.db.models
import
Count
from
django.db.models.signals
import
pre_save
,
post_save
from
django.dispatch
import
receiver
,
Signal
...
...
@@ -894,16 +894,32 @@ class CourseEnrollment(models.Model):
if
user
.
id
is
None
:
user
.
save
()
enrollment
,
created
=
CourseEnrollment
.
objects
.
get_or_create
(
user
=
user
,
course_id
=
course_key
,
)
try
:
enrollment
,
created
=
CourseEnrollment
.
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
=
"honor"
enrollment
.
is_active
=
False
enrollment
.
save
()
# If we *did* just create a new enrollment, set some defaults
if
created
:
enrollment
.
mode
=
"honor"
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
)
transaction
.
commit
()
enrollment
=
CourseEnrollment
.
objects
.
get
(
user
=
user
,
course_id
=
course_key
,
)
return
enrollment
...
...
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