Skip to content

Commit

Permalink
MDL-74032 core_cache: Coding error before upgrade with versioned cache
Browse files Browse the repository at this point in the history
In certain cases where it doesn't already redirect to run the upgrade,
users could see an exception 'Unexpectedly found non-versioned cache
entry'. This change ensures the upgrade happens instead.
  • Loading branch information
sammarshallou committed Mar 9, 2022
1 parent 1d99ba1 commit 3776b55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions cache/classes/loaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,16 @@ protected function get_implementation($key, int $requiredversion, int $strictnes
try {
$validversion = self::check_version($result, $requiredversion);
} catch (\coding_exception $e) {
// If we get an exception because there is incorrect data in the cache (not
// In certain circumstances this could happen before users are taken to the upgrade
// screen when upgrading from an earlier Moodle version that didn't use a versioned
// cache for this item, so redirect instead of showing error if that's the case.
redirect_if_major_upgrade_required();

// If we still get an exception because there is incorrect data in the cache (not
// versioned when it ought to be), delete it so this exception goes away next time.
// The exception should only happen if there is a code bug (which is why we still
// throw it) but there are unusual scenarios where it might happen and that would
// be annoying if it doesn't fix itself.
// throw it) but there are unusual scenarios in development where it might happen
// and that would be annoying if it doesn't fix itself.
$this->store->delete($parsedkey);
throw $e;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/setuplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ function disable_output_buffering() {
*/
function is_major_upgrade_required() {
global $CFG;
$lastmajordbchanges = 2021101900.01;
$lastmajordbchanges = 2022022200.00;

$required = empty($CFG->version);
$required = $required || (float)$CFG->version < $lastmajordbchanges;
Expand Down

0 comments on commit 3776b55

Please sign in to comment.