Skip to content

Commit 218f485

Browse files
authored
Merge pull request #2273 from drgrice1/bugfix/jitar-forusers-no-problem-record
Fix issue #2272.
2 parents 59998c6 + c70ae20 commit 218f485

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -852,20 +852,17 @@ sub fieldHTML ($c, $userID, $setID, $problemID, $globalRecord, $userRecord, $fie
852852
my @uVals;
853853
my @bVals;
854854
for my $f (split(/:/, $field)) {
855-
# Hmm. This directly references the data in the record rather than calling the access method, thereby
856-
# avoiding errors if the access method is undefined. That seems a bit suspect, but it's used below so we'll
857-
# leave it here.
858-
push(@gVals, $globalRecord->{$f});
859-
push(@uVals, $userRecord->{$f});
855+
push(@gVals, $globalRecord->can($f) ? $globalRecord->$f : undef);
856+
push(@uVals, $userRecord && $userRecord->can($f) ? $userRecord->$f : undef);
860857
push(@bVals, '');
861858
}
862859
# I don't like this, but combining multiple values is a bit messy
863860
$globalValue = (grep {defined} @gVals) ? join(':', (map { defined ? $_ : '' } @gVals)) : undef;
864861
$userValue = (grep {defined} @uVals) ? join(':', (map { defined ? $_ : '' } @uVals)) : undef;
865862
$blankfield = join(':', @bVals);
866863
} else {
867-
$globalValue = $globalRecord->{$field};
868-
$userValue = $userRecord->{$field};
864+
$globalValue = $globalRecord->can($field) ? $globalRecord->$field : undef;
865+
$userValue = $userRecord && $userRecord->can($field) ? $userRecord->$field : undef;
869866
}
870867

871868
# Use defined instead of value in order to allow 0 to printed, e.g. for the 'value' field.
@@ -956,11 +953,17 @@ sub fieldHTML ($c, $userID, $setID, $problemID, $globalRecord, $userRecord, $fie
956953
my @fields = split(/:/, $field);
957954
my @part_values;
958955
for (@fields) {
959-
push(@part_values, $forUsers && $userRecord->$_ ne '' ? $userRecord->$_ : $globalRecord->$_);
956+
push(@part_values,
957+
($forUsers && $userRecord && $userRecord->can($_) && $userRecord->$_ ne '')
958+
? $userRecord->$_
959+
: $globalRecord->$_);
960960
}
961961
$value = join(':', @part_values);
962962
} elsif (!$value) {
963-
$value = ($forUsers && $userRecord->$field ne '' ? $userRecord->$field : $globalRecord->$field);
963+
$value =
964+
($forUsers && $userRecord && $userRecord->can($field) && $userRecord->$field ne '')
965+
? $userRecord->$field
966+
: $globalRecord->$field;
964967
}
965968

966969
$inputType = $c->select_field(

0 commit comments

Comments
 (0)