diff --git a/lib/datalib.php b/lib/datalib.php
index <HASH>..<HASH> 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -567,7 +567,7 @@ function get_record_sql($sql, $expectmultiple=false, $nolimit=false) {
         $limit = '';
     } else if ($expectmultiple) {
         $limit = ' LIMIT 1';
-    } else if (isset($CFG->debug) && $CFG->debug) {
+    } else if (isset($CFG->debug) && $CFG->debug > 7) {
         // Debugging mode - don't use a limit of 1, but do change the SQL, because sometimes that
         // causes errors, and in non-debug mode you don't see the error message and it is 
         // impossible to know what's wrong.
Bug #<I> missing ' > 7' in debug test. Merged from MOODLE_<I>_STABLE.