Skip to content

Commit e714b1a

Browse files
authored
Merge pull request #1280 from jhamrick/fix-sqlite
Fix inappropriate use of sum with newer sqlite
2 parents 5268f5e + 34ef88e commit e714b1a

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: python
22
python:
33
- 3.5
44
- 3.6
5+
- 3.7
56
- nightly
67
env:
78
global:
@@ -14,10 +15,14 @@ matrix:
1415
exclude:
1516
- python: 3.5
1617
env: GROUP=docs
18+
- python: 3.6
19+
env: GROUP=docs
1720
- python: nightly
1821
env: GROUP=docs
1922
- python: 3.5
2023
env: GROUP=nbextensions
24+
- python: 3.6
25+
env: GROUP=nbextensions
2126
- python: nightly
2227
env: GROUP=nbextensions
2328
addons:

azure-pipelines.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ strategy:
1818
Python36:
1919
python.version: '3.6'
2020
testgroup: 'python'
21-
Python36Extensions:
22-
python.version: '3.6'
21+
Python37:
22+
python.version: '3.7'
23+
testgroup: 'python'
24+
Python37Extensions:
25+
python.version: '3.7'
2326
testgroup: 'nbextensions'
2427

2528
steps:

nbgrader/api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ def max_score(self):
841841
return self.max_score_taskcell
842842
else:
843843
return self.max_score_gradecell
844+
844845
#: Whether the autograded score is a result of failed autograder tests. This
845846
#: is True if the autograder score is zero and the cell type is "code", and
846847
#: otherwise False.
@@ -2962,7 +2963,13 @@ def student_dicts(self):
29622963
A list of dictionaries, one per student
29632964
29642965
"""
2965-
total_score, = self.db.query(func.sum(Assignment.max_score)).one()
2966+
max_scores = self.db.query(
2967+
Assignment.id,
2968+
func.sum(Assignment.max_score).label("max_score")
2969+
).group_by(Assignment.id).subquery()
2970+
_max_scores = func.coalesce(max_scores.c.max_score, 0.0)
2971+
total_score, = self.db.query(func.sum(_max_scores)).one()
2972+
29662973
if len(self.assignments) > 0 and total_score > 0:
29672974
# subquery the scores
29682975
scores = self.db.query(

nbgrader/tests/api/test_models.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,20 @@ def test_query_needs_manual_grade_manualgraded(submissions):
673673
def test_query_max_score(submissions):
674674
db = submissions[0]
675675

676-
assert [5, 10] == sorted([x[0] for x in db.query(api.GradeCell.max_score).all()])
677-
assert [5, 5, 10, 10] == sorted([x[1] for x in db.query(api.Grade.id, api.Grade.max_score).all()])
678-
assert [15] == sorted([x[1] for x in db.query(api.Notebook.id, api.Notebook.max_score).all()])
679-
assert [15, 15] == sorted([x[1] for x in db.query(api.SubmittedNotebook.id, api.SubmittedNotebook.max_score).all()])
680-
assert [15] == sorted([x[1] for x in db.query(api.Assignment.id, api.Assignment.max_score).all()])
681-
assert [15, 15] == sorted([x[1] for x in db.query(api.SubmittedAssignment.id, api.SubmittedAssignment.max_score).all()])
682-
assert [15, 15] == sorted([x[1] for x in db.query(api.Student.id, api.Student.max_score).all()])
676+
assert [5, 10] == sorted([x[1] for x in db.query(
677+
api.GradeCell.id, api.GradeCell.max_score).group_by(api.GradeCell.id).all()])
678+
assert [5, 5, 10, 10] == sorted([x[1] for x in db.query(
679+
api.Grade.id, api.Grade.max_score).group_by(api.Grade.id).all()])
680+
assert [15] == sorted([x[1] for x in db.query(
681+
api.Notebook.id, api.Notebook.max_score).group_by(api.Notebook.id).all()])
682+
assert [15, 15] == sorted([x[1] for x in db.query(
683+
api.SubmittedNotebook.id, api.SubmittedNotebook.max_score).group_by(api.SubmittedNotebook.id).all()])
684+
assert [15] == sorted([x[1] for x in db.query(
685+
api.Assignment.id, api.Assignment.max_score).group_by(api.Assignment.id).all()])
686+
assert [15, 15] == sorted([x[1] for x in db.query(
687+
api.SubmittedAssignment.id, api.SubmittedAssignment.max_score).group_by(api.SubmittedAssignment.id).all()])
688+
assert [15, 15] == sorted([x[1] for x in db.query
689+
(api.Student.id, api.Student.max_score).group_by(api.Student.id).all()])
683690

684691

685692
def test_query_score_ungraded(submissions):

0 commit comments

Comments
 (0)