Repository navigation
Conversation
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.
somiaj
approved these changes
Nov 17, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When the
PERSISTENCE_HASHis saved a fallback of'{}'is used inside theencode_jsoncall if thePERSISTENCE_HASHkey 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 theWeBWorK::Utils::Rendering::constructPGOptionsmethod decodes the data from the database, the JSON decoding step is performed in anevaland 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_rendercase from theWeBWorK::Utils::Rendering::renderPGmethod (an the correspondingGatewayQuizhandling of this) in which the problem completely fails and no PGcore object is even returned. In this case the current code saves theWeBWorK::Utils::ProblemProcessing::process_and_log_answermethod saves some things from the PG state that are guaranteed to be undefined (such as therecorded_score,num_of_correct_ans, andnum_of_incorrect_ans). So at the very least those should not be saved.