Skip to content

Fix saving of problem data (the persistence hash) when rendering fails. (hotfix of #3288) - #3292

Open
drgrice1 wants to merge 1 commit into
openwebwork:mainfrom
drgrice1:bugfix/problem-data-hotfix
Open

drgrice1 wants to merge 1 commit into
openwebwork:mainfrom
drgrice1:bugfix/problem-data-hotfix

Conversation

@drgrice1

Copy link
Copy Markdown
Member

When the PERSISTENCE_HASH is saved a fallback of '{}' is used inside the encode_json call if the PERSISTENCE_HASH key is undefined (or falsy). That encodes to the string "{}", and that string (literally including the quotes) is stored in the database. That is later decoded back to the string {} instead of the empty hash. In this case scaffolding problems throw an exception early in the pg post content processing phase that make it so that all parts of the scaffold are shown (with no scaffolding) and MathQuill answers are not injected, and all sorts of things fall apart. So this uses an anonymous hash instead as it should have. Furthermore, as a precaution when the WeBWorK::Utils::Rendering::constructPGOptions method decodes the data from the database, the JSON decoding step is performed in an eval and a fallback empty hash is used if the decoding fails (this will catch already stored invalid values).

This can happen, for instance, if a problem fails to render, but a student submits answers anyway. This actually happened in one of my classes.

There is further work to do in the case that a problem fails to render in general. We need to investigate what really should be saved in this case. This is the fail_render case from the WeBWorK::Utils::Rendering::renderPG method (an the corresponding GatewayQuiz handling of this) in which the problem completely fails and no PGcore object is even returned. In this case the current code saves the WeBWorK::Utils::ProblemProcessing::process_and_log_answer method saves some things from the PG state that are guaranteed to be undefined (such as the recorded_score, num_of_correct_ans, and num_of_incorrect_ans). So at the very least those should not be saved.

When the `PERSISTENCE_HASH` is saved a fallback of `'{}'` is used inside
the `encode_json` call if the `PERSISTENCE_HASH` key is undefined (or
falsy). That encodes to the string `"{}"`, and that string (literally
including the quotes) is stored in the database. That is later decoded
back to the string `{}` instead of the empty hash.  In this case
scaffolding problems throw an exception early in the pg post content
processing phase that make it so that all parts of the scaffold are
shown (with no scaffolding) and MathQuill answers are not injected, and
all sorts of things fall apart.  So this uses an anonymous hash instead
as it should have.  Furthermore, as a precaution when the
`WeBWorK::Utils::Rendering::constructPGOptions` method decodes the data
from the database, the JSON decoding step is performed in an `eval` and
a fallback empty hash is used if the decoding fails (this will catch
already stored invalid values).

This can happen, for instance, if a problem fails to render, but a
student submits answers anyway. This actually happened in one of my
classes.

There is further work to do in the case that a problem fails to render
in general. We need to investigate what really should be saved in this
case.  This is the `fail_render` case from the `WeBWorK::Utils::Rendering::renderPG`
method (an the corresponding `GatewayQuiz` handling of this) in which
the problem completely fails and no PGcore object is even returned.  In
this case the current code saves the `WeBWorK::Utils::ProblemProcessing::process_and_log_answer`
method saves some things from the PG state that are guaranteed to be
undefined (such as the `recorded_score`, `num_of_correct_ans`, and
`num_of_incorrect_ans`).  So at the very least those should not be
saved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants