Moodle

Cannot add a new field to a table with the XMLDB editor

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Cannot Reproduce
  • Affects Version/s: 2.0
  • Fix Version/s: 2.0
  • Component/s: Database SQL/XMLDB
  • Labels:
    None
  • Affected Branches:
    MOODLE_20_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

Try to add a new field called questiondecimalpoints int(4) signed not null default -1 with comment "The number of decimal digits to use when displaying question grades. -1 = use decimalpoints, otherwise a separate setting."

I get the error:

Fatal error: Call to a member function getHash() on a non-object in /home/tim/Workspace/moodle_head/admin/xmldb/actions/edit_field_save/edit_field_save.class.php on line 109

This is becuase XMLDB is trying to get the old hash of the field, so it can later see if anything has changed. However, the previous line $table->getField returns NULL, since this is a new field that was not present in the old structure.

Strangely, this code has not changed since it was added to core in August 2006: http://cvs.moodle.org/moodle/admin/xmldb/actions/edit_field_save/edit_field_save.class.php?hideattic=0&revision=1.1&view=markup

Similarly, the method table->getField, although it has moved several times, has not changed at all: http://cvs.moodle.org/moodle/lib/xmldb/classes/XMLDBTable.class.php?hideattic=0&revision=1.22&view=markup, and it has always returned null in this situation.

So, how the hell did it ever used to work. More to the point, why is it that every time I try to use XMLDB, it seems like I have to fix some bugs in it first?

/me goes to edit the XML by hand and swear and curse about the stupid, unnecessary, prev and next attributes.

Activity

Hide
Tim Hunt added a comment -

Grrrrrrrrrrrrrrrrrrrrr!

Just hit this again.

Please fix.

Please, please, please!

Show
Tim Hunt added a comment - Grrrrrrrrrrrrrrrrrrrrr! Just hit this again. Please fix. Please, please, please!
Hide
Tim Hunt added a comment -

Ah, the bug occurs if you add a new table, then immediately try to add a field.

If you add a new table, save the XML file, then reload the XML file, you can add a field.

Show
Tim Hunt added a comment - Ah, the bug occurs if you add a new table, then immediately try to add a field. If you add a new table, save the XML file, then reload the XML file, you can add a field.
Hide
Eloy Lafuente (stronk7) added a comment -

From Tim, HQ chat:

"I think the problem is with multiple broswer tabs. For example, if you go and look at the definition to another field to see what type it is. That then causes an error when you save the one you are working on."

review the flow of that info... it shouldn't rely on session at all.

Show
Eloy Lafuente (stronk7) added a comment - From Tim, HQ chat: "I think the problem is with multiple broswer tabs. For example, if you go and look at the definition to another field to see what type it is. That then causes an error when you save the one you are working on." review the flow of that info... it shouldn't rely on session at all.
Hide
Eloy Lafuente (stronk7) added a comment -

Uhm,

I've been trying to reproduce this in all ways possible:

  • Create table, then field, back without saving
  • Create table, then field, save (both without modifying the default "changeme" names and modifying them)
  • Create and then, while editing the new field, in other tab (same session), look another exiting field specs (edit it, both saving and without saving)
  • Force multiple "new field" executions to see if something is being reused incorrectly

And I haven't been able to get any error like the described above. So I'm going to close this as cannot reproduce. Please, if you find some sequence causing it... reopen and comment!

Slightly offtopic: Some days ago, I discovered that Moodle 2.0 sessions weren't being closed properly (due to one error in the destructor)... perhaps that could be causing some malfunction in session data, specially affecting the XMLDB editor when using more that one tab/window. Just a thought, not sure.

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Uhm, I've been trying to reproduce this in all ways possible:
  • Create table, then field, back without saving
  • Create table, then field, save (both without modifying the default "changeme" names and modifying them)
  • Create and then, while editing the new field, in other tab (same session), look another exiting field specs (edit it, both saving and without saving)
  • Force multiple "new field" executions to see if something is being reused incorrectly
And I haven't been able to get any error like the described above. So I'm going to close this as cannot reproduce. Please, if you find some sequence causing it... reopen and comment! Slightly offtopic: Some days ago, I discovered that Moodle 2.0 sessions weren't being closed properly (due to one error in the destructor)... perhaps that could be causing some malfunction in session data, specially affecting the XMLDB editor when using more that one tab/window. Just a thought, not sure. Ciao
Hide
Tim Hunt added a comment -

OK. If I hit this again, I will reopen with full details. Thanks.

Show
Tim Hunt added a comment - OK. If I hit this again, I will reopen with full details. Thanks.
Hide
David Balch added a comment -

I haven't debugged, but I can reliably reproduce this on Moodle 1.9.5+ (Build: 20090724)...
Trying to add a field to mod/assignment/db/assignment fails.

Name: requirestudentdeclaration
Comment: Force the student to check a box following a statement about the work, e.g. not having plagiarized.
Type: int
Length: 2
Not null: not null
Default: 0

However, I was able to add a different field to mod/assignment/db/assignment_submissions.

Show
David Balch added a comment - I haven't debugged, but I can reliably reproduce this on Moodle 1.9.5+ (Build: 20090724)... Trying to add a field to mod/assignment/db/assignment fails. Name: requirestudentdeclaration Comment: Force the student to check a box following a statement about the work, e.g. not having plagiarized. Type: int Length: 2 Not null: not null Default: 0 However, I was able to add a different field to mod/assignment/db/assignment_submissions.
Hide
David Balch added a comment -

Ah, hadn't seen the comments - I tried adding the field without opening a tab to refer to another field, and it worked.

Show
David Balch added a comment - Ah, hadn't seen the comments - I tried adding the field without opening a tab to refer to another field, and it worked.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: