-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Check that email subtasks are known to the InstructorTask before executing. #1351
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,6 +147,34 @@ def initialize_subtask_info(entry, action_name, total_num, subtask_id_list): | |
| return task_progress | ||
|
|
||
|
|
||
| def check_subtask_is_valid(entry_id, current_task_id): | ||
| """ | ||
| Confirms that the current subtask is known to the InstructorTask. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment of why could the check fail, so a developer can figure out what to do or check if that is the case.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added below. |
||
|
|
||
| This may happen if a task that spawns subtasks is called twice with | ||
| the same task_id and InstructorTask entry_id. The set of subtasks | ||
| that are recorded in the InstructorTask from the first call get clobbered | ||
| by the the second set of subtasks. So when the first set of subtasks | ||
| actually run, they won't be found in the InstructorTask. | ||
|
|
||
| Raises a ValueError exception if not. | ||
| """ | ||
| entry = InstructorTask.objects.get(pk=entry_id) | ||
| if len(entry.subtasks) == 0: | ||
| format_str = "Unexpected task_id '{}': unable to find email subtasks of instructor task '{}'" | ||
| msg = format_str.format(current_task_id, entry) | ||
| TASK_LOG.warning(msg) | ||
| raise ValueError(msg) | ||
|
|
||
| subtask_dict = json.loads(entry.subtasks) | ||
| subtask_status_info = subtask_dict['status'] | ||
| if current_task_id not in subtask_status_info: | ||
| format_str = "Unexpected task_id '{}': unable to find status for email subtask of instructor task '{}'" | ||
| msg = format_str.format(current_task_id, entry) | ||
| TASK_LOG.warning(msg) | ||
| raise ValueError(msg) | ||
|
|
||
|
|
||
| @transaction.commit_manually | ||
| def update_subtask_status(entry_id, current_task_id, new_subtask_status): | ||
| """ | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% clear why we know it's the exact same task that's called and not another, new task that is spawned. I feel I'm missing some puzzle piece...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree, it probably requires further investigation. However, if this has to be release soon I am ok with leaving it as it is provided we come back to figure out the problem later. Seems like something worth fixing going down the road.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The task is defined by the InstructorTask object. It contains the task_type, the task_id, and the input values. If that InstructorTask object arrives at this point in the code, and we find that it already contains subtasks, then we know we don't need to define subtasks for it. (I check the output because I need it to exist before returning successfully.) And there's really no other place where the subtasks would come from, and even if they did (because something was horribly wrong), it wouldn't make sense to write over them anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that makes sense. thanks.