From 4ed2c5d18681db43fb40fe2bab6f90b66ea989be Mon Sep 17 00:00:00 2001 From: Pan Luo Date: Fri, 10 Jul 2026 21:45:49 -0700 Subject: [PATCH] Prevent Caliper problem entity from dying on problem-group source files Problems selected from a problem group have the pseudo source file "group:problemGroupName" (see WeBWorK::Utils::Instructor::assignProblemToUserSetVersion), which is not a real file under the course templates directory. Caliper::Entity::problem unconditionally passed that path to WeBWorK::Utils::Tags->new, which dies when it cannot open the file, so any Caliper event embedding the problem entity (e.g. answer submission in a gateway quiz that uses problem groups) crashed server side. Skip tag parsing for "group:" pseudo source files instead. For those problems the entity now reports keywords => [] and tags => undef. Real problem files are unaffected: their keywords and unblessed tags are built exactly as before. --- lib/Caliper/Entity.pm | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/Caliper/Entity.pm b/lib/Caliper/Entity.pm index de991e8444..6275a50658 100644 --- a/lib/Caliper/Entity.pm +++ b/lib/Caliper/Entity.pm @@ -193,13 +193,20 @@ sub problem { my $problem = $db->getGlobalProblem($set_id, $problem_id); - my $templateDir = $ce->{courseDirs}->{templates}; - my $tags = WeBWorK::Utils::Tags->new($templateDir . '/' . $problem->source_file()); - my $keywords = $tags->{'keywords'}; - $_ =~ s/(^[\s"']+)|([\s"']+$)//g for @$keywords; - - my %tags_ref = %$tags; - my $unblessed_tags = \%tags_ref; + my $keywords = []; + my $unblessed_tags; + + # Problem groups use a "group:problemGroupName" pseudo source file (see + # WeBWorK::Utils::Instructor::assignProblemToUserSetVersion) which is not a real file, so attempting to read tags + # from it would die. + if ($problem->source_file() !~ /^group:/) { + my $templateDir = $ce->{courseDirs}->{templates}; + my $tags = WeBWorK::Utils::Tags->new($templateDir . '/' . $problem->source_file()); + $keywords = $tags->{'keywords'}; + $_ =~ s/(^[\s"']+)|([\s"']+$)//g for @$keywords; + + $unblessed_tags = {%$tags}; + } return { 'id' => $resource_iri->problem($set_id, $problem_id),