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
0e2534f3
Commit
0e2534f3
authored
Nov 22, 2016
by
J. Cliff Dyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrap update_or_create in transaction to allow validation after save
parent
86c12e67
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
14 deletions
+15
-14
lms/djangoapps/grades/models.py
+12
-11
lms/djangoapps/grades/tests/test_tasks.py
+3
-3
No files found.
lms/djangoapps/grades/models.py
View file @
0e2534f3
...
...
@@ -16,7 +16,7 @@ from lazy import lazy
import
logging
from
django.core.exceptions
import
ValidationError
from
django.db
import
models
from
django.db
import
models
,
transaction
from
django.utils.timezone
import
now
from
model_utils.models
import
TimeStampedModel
...
...
@@ -330,16 +330,17 @@ class PersistentSubsectionGrade(TimeStampedModel):
user_id
=
kwargs
.
pop
(
'user_id'
)
usage_key
=
kwargs
.
pop
(
'usage_key'
)
attempted
=
kwargs
.
pop
(
'attempted'
)
grade
,
_
=
cls
.
objects
.
update_or_create
(
user_id
=
user_id
,
course_id
=
usage_key
.
course_key
,
usage_key
=
usage_key
,
defaults
=
kwargs
,
)
if
attempted
and
not
grade
.
first_attempted
:
grade
.
first_attempted
=
now
()
grade
.
full_clean
()
grade
.
save
()
with
transaction
.
atomic
():
grade
,
_
=
cls
.
objects
.
update_or_create
(
user_id
=
user_id
,
course_id
=
usage_key
.
course_key
,
usage_key
=
usage_key
,
defaults
=
kwargs
,
)
if
attempted
and
not
grade
.
first_attempted
:
grade
.
first_attempted
=
now
()
grade
.
save
()
grade
.
full_clean
()
return
grade
@classmethod
...
...
lms/djangoapps/grades/tests/test_tasks.py
View file @
0e2534f3
...
...
@@ -113,7 +113,7 @@ class RecalculateSubsectionGradeTest(ModuleStoreTestCase):
with
self
.
store
.
default_store
(
default_store
):
self
.
set_up_course
()
self
.
assertTrue
(
PersistentGradesEnabledFlag
.
feature_enabled
(
self
.
course
.
id
))
with
check_mongo_calls
(
2
)
and
self
.
assertNumQueries
(
2
3
+
added_queries
):
with
check_mongo_calls
(
2
)
and
self
.
assertNumQueries
(
2
4
+
added_queries
):
self
.
_apply_recalculate_subsection_grade
()
@patch
(
'lms.djangoapps.grades.signals.signals.SUBSECTION_SCORE_CHANGED.send'
)
...
...
@@ -161,7 +161,7 @@ class RecalculateSubsectionGradeTest(ModuleStoreTestCase):
self
.
assertTrue
(
PersistentGradesEnabledFlag
.
feature_enabled
(
self
.
course
.
id
))
ItemFactory
.
create
(
parent
=
self
.
sequential
,
category
=
'problem'
,
display_name
=
'problem2'
)
ItemFactory
.
create
(
parent
=
self
.
sequential
,
category
=
'problem'
,
display_name
=
'problem3'
)
with
check_mongo_calls
(
2
)
and
self
.
assertNumQueries
(
2
3
+
added_queries
):
with
check_mongo_calls
(
2
)
and
self
.
assertNumQueries
(
2
4
+
added_queries
):
self
.
_apply_recalculate_subsection_grade
()
@ddt.data
(
ModuleStoreEnum
.
Type
.
mongo
,
ModuleStoreEnum
.
Type
.
split
)
...
...
@@ -172,7 +172,7 @@ class RecalculateSubsectionGradeTest(ModuleStoreTestCase):
with
check_mongo_calls
(
2
)
and
self
.
assertNumQueries
(
0
):
self
.
_apply_recalculate_subsection_grade
()
#
@skip("Pending completion of TNL-5089")
@skip
(
"Pending completion of TNL-5089"
)
@ddt.data
(
(
ModuleStoreEnum
.
Type
.
mongo
,
True
),
(
ModuleStoreEnum
.
Type
.
split
,
True
),
...
...
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