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

Invalid characters in import groups file fail the process with the confusing error message

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.0.1, 2.8.1
    • Fix Version/s: STABLE backlog
    • Component/s: Groups
    • Labels:
    • Affected Branches:
      MOODLE_20_STABLE, MOODLE_28_STABLE

      Description

      Import Groups from the .csv fails in Moodle 2.0.1+ (Build: 20110209)
      Tested on QA site with the file that works ok in 1.9 (attached)

      Error message:

      Error writing to database

      Debug info:
      Stack trace:

      • line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown
      • line 874 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
      • line 916 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
      • line 135 of /group/lib.php: call to mysqli_native_moodle_database->insert_record()
      • line 171 of /group/import.php: call to groups_create_group()

        Gliffy Diagrams

        1. import.csv
          0.0 kB
          Elena Ivanova

          Activity

          Hide
          skodak Petr Skoda added a comment -

          There is an invalid character at the end of the second line, that is the reason why it fails.

          I agree we should somehow validate the cvs files before storing the data in database....

          Show
          skodak Petr Skoda added a comment - There is an invalid character at the end of the second line, that is the reason why it fails. I agree we should somehow validate the cvs files before storing the data in database....
          Hide
          jago Jago Brown added a comment -

          feedback:

          on import of utf8 file to mdl 2.2.12 get error:
          15:08:28] Default exception handler: "groupname" is not a valid field name Debug:
          which appears to relate to the Byte Order Mark (BOM) - the representation for the UTF-8 BOM in ISO-8859-1

          http://stackoverflow.com/questions/3255993/how-do-i-remove-i-from-the-beginning-of-a-file

          what works is importing a ANSI encoded file using idnumber instead of (short)coursename

          Show
          jago Jago Brown added a comment - feedback: on import of utf8 file to mdl 2.2.12 get error: 15:08:28] Default exception handler: "groupname" is not a valid field name Debug: which appears to relate to the Byte Order Mark (BOM) - the representation for the UTF-8 BOM in ISO-8859-1 http://stackoverflow.com/questions/3255993/how-do-i-remove-i-from-the-beginning-of-a-file what works is importing a ANSI encoded file using idnumber instead of (short)coursename
          Hide
          libertymoodle Luis de Vasconcelos added a comment - - edited

          In Moodle 2.5.3+ (Build: 20131129) my group import file contains:

          groupname,description
          group1,testing group 1
          group2,testing group 2
          group3,testing group 3

          When I import that file into a course via http://mysite/group/import.php?id=123 I get the following error:

          "groupname" is not a valid field name

          Debug info:
          Error code: invalidfieldname
          Stack trace:

          line 476 of \lib\setuplib.php: moodle_exception thrown
          line 94 of \group\import.php: call to print_error()

          The Help topic on the /group/import.php?id=123 page says:
          "Required fieldname is groupname"
          so "groupname" has to be valid.

          And line 78/79 of \group\import.php contains:

          // make arrays of valid fields for error checking
          $required = array("groupname" => 1);

          So again, "groupname" seems to be the correct fieldname.

          Why then does Moodle crash with the '"groupname" is not a valid field name' error when clearly "groupname" is the valid field name?

          Show
          libertymoodle Luis de Vasconcelos added a comment - - edited In Moodle 2.5.3+ (Build: 20131129) my group import file contains: groupname,description group1,testing group 1 group2,testing group 2 group3,testing group 3 When I import that file into a course via http://mysite/group/import.php?id=123 I get the following error: "groupname" is not a valid field name Debug info: Error code: invalidfieldname Stack trace: line 476 of \lib\setuplib.php: moodle_exception thrown line 94 of \group\import.php: call to print_error() The Help topic on the /group/import.php?id=123 page says: "Required fieldname is groupname" so "groupname" has to be valid. And line 78/79 of \group\import.php contains: // make arrays of valid fields for error checking $required = array("groupname" => 1); So again, "groupname" seems to be the correct fieldname. Why then does Moodle crash with the '"groupname" is not a valid field name' error when clearly "groupname" is the valid field name?
          Hide
          ellavs Ella added a comment -

          I get the same error: "groupname" is not a valid field name
          Moodle 2.8.1 (Build: 20141113)

          Show
          ellavs Ella added a comment - I get the same error: "groupname" is not a valid field name Moodle 2.8.1 (Build: 20141113)
          Hide
          marina Marina Glancy added a comment -

          Thanks, I changed the summary of the issue and added to our backlog.

          The problem here seem to be in invalid characters in the file, like Petr noticed.
          It will be up to the developer whether to automatically strip invalid characters from the header line and proceed or just fail the whole import process.

          Also I've noticed that the attached csv file on 2.8 gives a different error message than reported - Error writing to database

          Show
          marina Marina Glancy added a comment - Thanks, I changed the summary of the issue and added to our backlog. The problem here seem to be in invalid characters in the file, like Petr noticed. It will be up to the developer whether to automatically strip invalid characters from the header line and proceed or just fail the whole import process. Also I've noticed that the attached csv file on 2.8 gives a different error message than reported - Error writing to database

            People

            • Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated: