Skip to content

Commit ab7ef18

Browse files
authored
Resolve warnings in SQLAlchemy field defs (#1963)
Most notably, Grade.cell_type was defined as an association_proxy in the class, but was later overwritten with a column_property. Because the mapper had already been made aware of the association_proxy, this raised a warning. Grade.max_score also had a similar problem, with a column_property overwriting a regular @Property. This commit fixes the warnings by replacing the in-class field definitions with `field = None`. Additionally, remove duplicate definitions for `cell_type_gradecell` and `cell_type_taskcell`. Fixes #1946
1 parent 99e145b commit ab7ef18

File tree

1 file changed

+7
-33
lines changed

1 file changed

+7
-33
lines changed

nbgrader/api.py

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,8 @@ class Grade(Base):
766766
cell_id = Column(String(32), ForeignKey('base_cell.id'))
767767

768768
#: The type of cell this grade corresponds to, inherited from
769-
#: :class:`~nbgrader.api.GradeCell`
770-
cell_type = association_proxy('cell', 'cell_type')
769+
#: :class:`~nbgrader.api.GradeCell` or :class:`~nbgrader.api.TaskCell`
770+
cell_type = None
771771

772772
#: The student who this grade is assigned to, represented by a
773773
#: :class:`~nbgrader.api.Student` object
@@ -798,15 +798,7 @@ class Grade(Base):
798798

799799
#: The maximum possible score that can be assigned, inherited from
800800
#: :class:`~nbgrader.api.GradeCell`
801-
max_score_gradecell = None
802-
max_score_taskcell = None
803-
804-
@property
805-
def max_score(self):
806-
if self.max_score_taskcell:
807-
return self.max_score_taskcell
808-
else:
809-
return self.max_score_gradecell
801+
max_score = None
810802

811803
#: Whether the autograded score is a result of failed autograder tests. This
812804
#: is True if the autograder score is zero and the cell type is "code", and
@@ -990,31 +982,10 @@ def __repr__(self):
990982
.where(Grade.cell_id == TaskCell.id)
991983
.correlate_except(TaskCell)
992984
.scalar_subquery(), deferred=True)
985+
993986
# a grade is either from a grade cell or a task cell , so only one will not be none
994987
Grade.max_score = column_property(func.coalesce(Grade.max_score_gradecell, Grade.max_score_taskcell, 0.0), deferred=True)
995988

996-
# try defining the cell_type_**** as athe result of a search as for the max_score
997-
# and not through the relationship
998-
999-
Grade.cell_type_from_taskcell = column_property(
1000-
select(TaskCell.cell_type)
1001-
.select_from(TaskCell)
1002-
.where(Grade.cell_id == TaskCell.id)
1003-
.correlate_except(TaskCell)
1004-
.scalar_subquery(), deferred=True)
1005-
1006-
Grade.cell_type_from_gradecell = column_property(
1007-
select(GradeCell.cell_type)
1008-
.select_from(GradeCell)
1009-
.where(Grade.cell_id == GradeCell.id)
1010-
.correlate_except(GradeCell)
1011-
.scalar_subquery(), deferred=True)
1012-
1013-
Grade.cell_type = column_property(
1014-
select(func.coalesce(Grade.cell_type_from_gradecell, Grade.cell_type_from_taskcell))
1015-
.scalar_subquery()
1016-
)
1017-
1018989

1019990
Notebook.max_score_gradecell = column_property(
1020991
select(func.coalesce(func.sum(GradeCell.max_score), 0.0))
@@ -1271,6 +1242,9 @@ def __repr__(self):
12711242
.correlate_except(TaskCell)
12721243
.scalar_subquery(), deferred=True)
12731244

1245+
Grade.cell_type = column_property(
1246+
func.coalesce(Grade.cell_type_gradecell, Grade.cell_type_taskcell)
1247+
)
12741248

12751249
# Failed tests
12761250

0 commit comments

Comments
 (0)