Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate grade_ids #1753

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nbgrader/converters/autograde.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ..preprocessors import (
AssignLatePenalties, ClearOutput, DeduplicateIds, OverwriteCells, SaveAutoGrades,
Execute, LimitOutput, OverwriteKernelspec, CheckCellMetadata, IgnorePattern)
from ..postprocessors import CheckDuplicateFlag
from ..api import Gradebook, MissingEntry
from .. import utils

Expand Down Expand Up @@ -196,3 +197,6 @@ def convert_single_notebook(self, notebook_filename: str) -> None:
super(Autograde, self).convert_single_notebook(notebook_filename)
finally:
self._sanitizing = True

self.log.info(f"Post-processing {notebook_filename}")
CheckDuplicateFlag(notebook_filename)
44 changes: 30 additions & 14 deletions nbgrader/converters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ..coursedir import CourseDirectory
from ..utils import find_all_files, rmtree, remove
from ..preprocessors.execute import UnresponsiveKernelError
from ..postprocessors import DuplicateIdError
from ..nbgraderformat import SchemaTooOldError, SchemaTooNewError
import typing
from nbconvert.exporters.exporter import ResourcesDict
Expand Down Expand Up @@ -387,25 +388,40 @@ def _handle_failure(gd: typing.Dict[str, str]) -> None:

# convert all the notebooks
for notebook_filename in self.notebooks:
self.convert_single_notebook(notebook_filename)
try:
self.convert_single_notebook(notebook_filename)

# Exceptions that shouldn't interrupt the entire conversion process should go here
# Those that should interrupt go in the outer try/except
except UnresponsiveKernelError:
self.log.error(
"While processing assignment %s, the kernel became "
"unresponsive and we could not interrupt it. This probably "
"means that the students' code has an infinite loop that "
"consumes a lot of memory or something similar. nbgrader "
"doesn't know how to deal with this problem, so you will "
"have to manually edit the students' code (for example, to "
"just throw an error rather than enter an infinite loop). ",
assignment)
errors.append((gd['assignment_id'], gd['student_id']))
_handle_failure(gd)

except DuplicateIdError:
self.log.error(
f"Encountered a cell with duplicate id when processing {notebook_filename}. "
"Autograding with skipping cells marked as duplicate."
)
errors.append((gd['assignment_id'], gd['student_id']))

# Raise unhandled exceptions for the outer try/except
except Exception as e:
raise e

# set assignment permissions
self.set_permissions(gd['assignment_id'], gd['student_id'])
self.run_post_convert_hook()

except UnresponsiveKernelError:
self.log.error(
"While processing assignment %s, the kernel became "
"unresponsive and we could not interrupt it. This probably "
"means that the students' code has an infinite loop that "
"consumes a lot of memory or something similar. nbgrader "
"doesn't know how to deal with this problem, so you will "
"have to manually edit the students' code (for example, to "
"just throw an error rather than enter an infinite loop). ",
assignment)
errors.append((gd['assignment_id'], gd['student_id']))
_handle_failure(gd)

# Exceptions that should interrupt the entire conversion go here
except sqlalchemy.exc.OperationalError:
_handle_failure(gd)
self.log.error(traceback.format_exc())
Expand Down
5 changes: 5 additions & 0 deletions nbgrader/coursedir.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import re
import sys

from textwrap import dedent

Expand Down Expand Up @@ -338,3 +339,7 @@ def get_existing_timestamp(self, dest_path: str) -> Optional[datetime.datetime]:
"Invalid timestamp string: {}".format(timestamp_path))
else:
return None

def fail(self, msg, *args):
self.log.error(msg, *args)
sys.exit(1)
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"grade": false,
"grade_id": "jupyter",
"locked": true,
"schema_version": 3,
"schema_version": 4,
"solution": false
}
},
Expand Down Expand Up @@ -66,7 +66,7 @@
"grade": false,
"grade_id": "squares",
"locked": false,
"schema_version": 3,
"schema_version": 4,
"solution": true
}
},
Expand Down Expand Up @@ -124,7 +124,7 @@
"grade_id": "correct_squares",
"locked": false,
"points": 1.0,
"schema_version": 3,
"schema_version": 4,
"solution": false
}
},
Expand Down Expand Up @@ -161,7 +161,7 @@
"grade_id": "squares_invalid_input",
"locked": false,
"points": 1.0,
"schema_version": 3,
"schema_version": 4,
"solution": false
}
},
Expand Down Expand Up @@ -205,7 +205,7 @@
"grade": false,
"grade_id": "sum_of_squares",
"locked": false,
"schema_version": 3,
"schema_version": 4,
"solution": true
}
},
Expand Down Expand Up @@ -259,7 +259,7 @@
"grade_id": "correct_sum_of_squares",
"locked": false,
"points": 0.5,
"schema_version": 3,
"schema_version": 4,
"solution": false
},
"tags": [
Expand Down Expand Up @@ -299,7 +299,7 @@
"grade_id": "sum_of_squares_uses_squares",
"locked": false,
"points": 0.5,
"schema_version": 3,
"schema_version": 4,
"solution": false
}
},
Expand Down Expand Up @@ -339,7 +339,7 @@
"grade_id": "sum_of_squares_equation",
"locked": false,
"points": 1.0,
"schema_version": 3,
"schema_version": 4,
"solution": true
}
},
Expand Down Expand Up @@ -369,7 +369,7 @@
"grade_id": "sum_of_squares_application",
"locked": false,
"points": 2.0,
"schema_version": 3,
"schema_version": 4,
"solution": true
},
"tags": [
Expand Down Expand Up @@ -403,7 +403,7 @@
"grade_id": "cell-938593c4a215c6cc",
"locked": true,
"points": 4,
"schema_version": 3,
"schema_version": 4,
"solution": false,
"task": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"grade_id": "part-a",
"locked": false,
"points": 1.0,
"schema_version": 3,
"schema_version": 4,
"solution": true
}
},
Expand Down Expand Up @@ -90,7 +90,7 @@
"grade_id": "part-b",
"locked": false,
"points": 2.0,
"schema_version": 3,
"schema_version": 4,
"solution": true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"grade": false,
"grade_id": "jupyter",
"locked": true,
"schema_version": 3,
"schema_version": 4,
"solution": false
}
},
Expand Down Expand Up @@ -66,7 +66,7 @@
"grade": false,
"grade_id": "squares",
"locked": false,
"schema_version": 3,
"schema_version": 4,
"solution": true
}
},
Expand Down Expand Up @@ -121,7 +121,7 @@
"grade_id": "correct_squares",
"locked": false,
"points": 1.0,
"schema_version": 3,
"schema_version": 4,
"solution": false
}
},
Expand All @@ -146,7 +146,7 @@
"grade_id": "squares_invalid_input",
"locked": false,
"points": 1.0,
"schema_version": 3,
"schema_version": 4,
"solution": false
}
},
Expand Down Expand Up @@ -190,7 +190,7 @@
"grade": false,
"grade_id": "sum_of_squares",
"locked": false,
"schema_version": 3,
"schema_version": 4,
"solution": true
}
},
Expand Down Expand Up @@ -240,7 +240,7 @@
"grade_id": "correct_sum_of_squares",
"locked": false,
"points": 0.5,
"schema_version": 3,
"schema_version": 4,
"solution": false
}
},
Expand All @@ -265,7 +265,7 @@
"grade_id": "sum_of_squares_uses_squares",
"locked": false,
"points": 0.5,
"schema_version": 3,
"schema_version": 4,
"solution": false
}
},
Expand Down Expand Up @@ -305,7 +305,7 @@
"grade_id": "sum_of_squares_equation",
"locked": false,
"points": 1.0,
"schema_version": 3,
"schema_version": 4,
"solution": true
}
},
Expand Down Expand Up @@ -335,7 +335,7 @@
"grade_id": "sum_of_squares_application",
"locked": false,
"points": 2.0,
"schema_version": 3,
"schema_version": 4,
"solution": true
}
},
Expand Down Expand Up @@ -405,7 +405,7 @@
"grade_id": "cell-938593c4a215c6cc",
"locked": true,
"points": 4,
"schema_version": 3,
"schema_version": 4,
"solution": false,
"task": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"grade_id": "part-a",
"locked": false,
"points": 1.0,
"schema_version": 3,
"schema_version": 4,
"solution": true
}
},
Expand Down Expand Up @@ -90,7 +90,7 @@
"grade_id": "part-b",
"locked": false,
"points": 2.0,
"schema_version": 3,
"schema_version": 4,
"solution": true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"grade": false,
"grade_id": "jupyter",
"locked": true,
"schema_version": 2,
"schema_version": 4,
"solution": false
}
},
Expand Down Expand Up @@ -66,7 +66,7 @@
"grade": false,
"grade_id": "squares",
"locked": false,
"schema_version": 2,
"schema_version": 4,
"solution": true
}
},
Expand Down Expand Up @@ -110,7 +110,7 @@
"grade_id": "correct_squares",
"locked": false,
"points": 1.0,
"schema_version": 2,
"schema_version": 4,
"solution": false
}
},
Expand All @@ -135,7 +135,7 @@
"grade_id": "squares_invalid_input",
"locked": false,
"points": 1.0,
"schema_version": 2,
"schema_version": 4,
"solution": false
}
},
Expand Down Expand Up @@ -179,7 +179,7 @@
"grade": false,
"grade_id": "sum_of_squares",
"locked": false,
"schema_version": 2,
"schema_version": 4,
"solution": true
}
},
Expand Down Expand Up @@ -218,7 +218,7 @@
"grade_id": "correct_sum_of_squares",
"locked": false,
"points": 0.5,
"schema_version": 2,
"schema_version": 4,
"solution": false
}
},
Expand All @@ -243,7 +243,7 @@
"grade_id": "sum_of_squares_uses_squares",
"locked": false,
"points": 0.5,
"schema_version": 2,
"schema_version": 4,
"solution": false
}
},
Expand Down Expand Up @@ -283,7 +283,7 @@
"grade_id": "sum_of_squares_equation",
"locked": false,
"points": 1.0,
"schema_version": 2,
"schema_version": 4,
"solution": true
}
},
Expand Down Expand Up @@ -313,7 +313,7 @@
"grade_id": "sum_of_squares_application",
"locked": false,
"points": 2.0,
"schema_version": 2,
"schema_version": 4,
"solution": true
}
},
Expand Down
Loading
Loading