Skip to content

Commit 9e7e92e

Browse files
committed
Fix a potentially ambiguous column in SQL order by clauses.
In `WeBWorK::ContentGenerator::Instructor::UserDetail` and `WeBWorK::ContentGenerator::Instructor::ProblemSet` I used `q{(SUBSTRING(set_id,INSTR(set_id,',v')+2)+0)}` for the order by clause in `getMergedSetVersionsWhere` calls. The problem is that `getMergedSetVersionsWhere` performs an inner join on the row from the `user_set` table that is the user's versioned set, the row from that same table that is the user's template set, and the global template set from the `set` tabel. Apparently some database configurations are lenient and assume the first table, but others do not. So this replaces that with `grok_versionID_from_vsetID_sql($db->{set_version_merged}->sql->_quote('set_id'))`. The `_quote` call ensures that the `set_id` column is selected from the primary table (the row that is the user's versioned set) since it is passed through the `transform_all` method of `WeBWorK::DB::Schema::NewSQL::Merge`. This will most likely fix #2341. Although I am can't (easily) test this, and can't reproduce the issue reported there. I suspect that this occurs when `mysql` is used instead of `MariaDB`. I suspect that `MariaDB` is more lenient on this.
1 parent 0d9f5e2 commit 9e7e92e

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

lib/WeBWorK/ContentGenerator/Instructor/UserDetail.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ WeBWorK::ContentGenerator::Instructor::UserDetail - Detailed User specific infor
2424

2525
use WeBWorK::Utils qw(x);
2626
use WeBWorK::Utils::Instructor qw(assignSetToUser);
27+
use WeBWorK::DB::Utils qw(grok_versionID_from_vsetID_sql);
2728
use WeBWorK::Debug;
2829

2930
# We use the x function to mark strings for localizaton
@@ -158,7 +159,7 @@ sub initialize ($c) {
158159
$c->{mergedVersions}{$setID} = [
159160
$db->getMergedSetVersionsWhere(
160161
{ user_id => $editForUserID, set_id => { like => "$setID,v\%" } },
161-
\q{(SUBSTRING(set_id,INSTR(set_id,',v')+2)+0)}
162+
\grok_versionID_from_vsetID_sql($db->{set_version_merged}->sql->_quote('set_id'))
162163
)
163164
];
164165
}

lib/WeBWorK/ContentGenerator/ProblemSet.pm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ problem set.
2626
use WeBWorK::Debug;
2727
use WeBWorK::Utils qw(path_is_subdir is_restricted wwRound before between after grade_set format_set_name_display);
2828
use WeBWorK::Utils::Rendering qw(renderPG);
29+
use WeBWorK::DB::Utils qw(grok_versionID_from_vsetID_sql);
2930
use WeBWorK::Localize;
3031

3132
async sub initialize ($c) {
@@ -195,9 +196,10 @@ sub gateway_body ($c) {
195196
my $timeInterval = $set->time_interval || 0;
196197
my @versionData;
197198

198-
my @setVersions =
199-
$db->getMergedSetVersionsWhere({ user_id => $effectiveUser, set_id => { like => $set->set_id . ',v%' } },
200-
\q{(SUBSTRING(set_id,INSTR(set_id,',v')+2)+0)});
199+
my @setVersions = $db->getMergedSetVersionsWhere(
200+
{ user_id => $effectiveUser, set_id => { like => $set->set_id . ',v%' } },
201+
\grok_versionID_from_vsetID_sql($db->{set_version_merged}->sql->_quote('set_id'))
202+
);
201203

202204
for my $verSet (@setVersions) {
203205
# Count number of versions in current timeInterval

0 commit comments

Comments
 (0)