Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-70757

XMLDB editor false positive warning for NUMERIC type

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • None
    • 3.9 regressions
    • Database SQL/XMLDB
    • None
    • MySQL
    • Easy

      Problem:

      XMLDB editor in the "Defaults" check in Moodle 3.9 insists that defaults are wrong where column type is NUMERIC:
      "Table: question_numerical_options. Field: unitpenalty, Expected '0.1' Actual '0.1000000'"

      After upgrading from 3.9.1 to 3.9.2 moodle is still showing this warnings.

      Recommended fix by XMLDB:

      The check suggests the following fix for example:

      ALTER TABLE mdl_question_numerical_options MODIFY COLUMN unitpenalty NUMERIC(12,7) NOT NULL DEFAULT 0.1 after unitgradingtype;

      MySQL shows the column as:

      `unitpenalty` decimal(12,7) NOT NULL DEFAULT '0.1000000',

      The suggested ALTER statement takes no effect as DECIMAL and NUMERIC are identical in MySQL. 

      Steps To Reproduce:

      Site adm -> Development -> XMLDB editor -> [Check defaults] on clean installation 3.9.1.

      Look for inconsistent default values
      [Back]

      Search results
      Wrong defaults found: 35

      My solution:

      The best solution is to add the fallowing code that repair this. It was added in newest versions, but not added  in my tests-case to version 3.9.1

      git diff origin/master – admin/tool/xmldb/actions/check_defaults/check_defaults.class.php

      admin/tool/xmldb/actions/check_defaults/check_defaults.class.php
      index ea21a1278a6..c37ab3670e4 100644
      — a/admin/tool/xmldb/actions/check_defaults/check_defaults.class.php
      +++ b/admin/tool/xmldb/actions/check_defaults/check_defaults.class.php
      @@ -93,17 +93,6 @@ class check_defaults extends XMLDBCheckAction

      {                      $physicaldefault = null;                  }

       

      • // For number fields there are issues with type differences, so let's convert
      • // everything to a float.
      • if ($xmldbfield->getType() === XMLDB_TYPE_NUMBER) {
      • if ($physicaldefault !== null) { - $physicaldefault = (float) $physicaldefault; - }
      • if ($xmldbdefault !== null) { - $xmldbdefault = (float) $xmldbdefault; - }
      • }
        -
                         // There is a default and it's wrong.
                         if ($physicaldefault !== $xmldbdefault) {
                             $xmldbtext = self::display_default($xmldbdefault);

            Unassigned Unassigned
            jakubkleban Jakub Kleban
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.