Bug: file upload dialog box not showing

Bug: file upload dialog box not showing

por Michael Fairbank -
Número de respuestas: 7

Not sure if this is a Moodle bug or a CodeRunner bug.  We are on the version 4+ of Moodle. 

This problem is for a coderunner question which allows users to upload an attachment (as defined in the "attachment options" part of the question definition).

The users are meant to see an upload panel like this:

image no bug

But in they see this:

image bug

The students are saying this problem is most noticeable when using Google Chrome, but sometimes when they reload the page the problem vanishes, with luck.  It seems more likely to vanish if I tell the students to switch over to Firefox.  But we have not tracked down exactly how to make this problem deterministic. 

This problem did not arise last year when I ran this question.  Any ideas?  Should I just report this to the Moodle developers? Or is it something that can be fixed at the CodeRunner end? Thanks!


En respuesta a Michael Fairbank

Re: Bug: file upload dialog box not showing

por Richard Lobb -
Thanks for reporting.

I'm afraid I can't replicate the problem. But I don't think it's a CodeRunner bug as I'm using standard Moodle library code to display the file upload box. The code to display the box is in a dynamically loaded script, which should be pulled in towards the end of the page display. Your screenshot seems to show the "waiting" icon suggesting that the browser is waiting for a response to its request for either dndupload.js or filemanager.js. Those are both Moodle library files, nothing to do with CodeRunner.

To confirm this you could switch on the browser developer tools (SHIFT+CTRL+I) and display the network tab. Then load the page and observe the browser chain of requests. That should show you what the browser is waiting on.

Another useful test would be to create an essay type question that requires the student to attach a document and see if that suffers the same problem. If so, it's certainly not CodeRunner and I can relax :)

Please let us know what you find.
En respuesta a Richard Lobb

Re: Bug: file upload dialog box not showing

por Michael Fairbank -
I've done a bit more research on this.
1. I created an essay question with an attachment requirement, but unfortunately could not get it to replicate the bug.
2. I could replicate the bug on the coderunner attachment (but only on Google Chrome; and only in about 50% of page refreshes did the bug occur). The bug never occurred on Firefox.
3. I managed to get an error message copied from the Chrome's debug mode's console window:

first.js:1752 Uncaught TypeError: Cannot read properties of null (reading 'closest')
at getFormFromChild (first.js:1752:108)
at watchForm (first.js:1752:155)
at watchFormById (first.js:1752:4934)
at Object.init (first.js:1752:4457)
at attempt.php?attempt=1404933&cmid=879541&page=2:2829:76
at YUI._notify (yui_combo.php?rollup/3.17.2/yui-moodlesimple-min.js:9:1495)
at YUI.T (yui_combo.php?rollup/3.17.2/yui-moodlesimple-min.js:9:2421)
at e.Loader._finish (yui_combo.php?rollup/3.17.2/yui-moodlesimple-min.js:16:4853)
at e.Loader._onSuccess (yui_combo.php?rollup/3.17.2/yui-moodlesimple-min.js:16:5367)
at e.Loader.p (yui_combo.php?rollup/3.17.2/yui-moodlesimple-min.js:17:1321)

This refers to a file called first.js, which seems to point to a php file which was too large to attach but I think it's standard stuff from a Moodle engine.

What I think is line 1752 of that first.js is attached in the .txt file, if that helps.

I'm happy to pass this on as a bug on Moodle if you advise it's not likely a coderunner issue.

Thank you!
En respuesta a Michael Fairbank

Re: Bug: file upload dialog box not showing

por Michael Fairbank -
We've just noticed something else relevant that might resolve this issue. We are getting a warning:

The moodle-core-formchangechecker has been deprecated and replaced with core_form/changechecker. Please update your code to make use of the new module.

Line 1752 refers to formchangechecker, so hopefully when we issue an update to address this deprecation issue that might resolve the problem. I'll keep you posted.
En respuesta a Michael Fairbank

Re: Bug: file upload dialog box not showing

por Richard Lobb -
Many thanks Michael. That was all very helpful. Indeed it does seem like this is a CodeRunner specific problem :-(

I have some code in the CodeRunner renderer that explicitly initialises the now-deprecated changechecker (which warns the user when they navigate away from an altered page). I think I can probably remove that code altogether since the spurious warnings that the code is intended to prevent no longer seem to occur on Moodle 4. However, I've only done a very quick check and far more investigation is needed to confirm that. It will probably have to wait a couple of weeks until our semester ends and I have more time for development.

If you're a system administrator, and you're the only one likely to be affected, you could try commenting out lines 625 through 628 of question/type/coderunner/renderer.php, namely the four lines

    $this->page->requires->yui_module('moodle-core-formchangechecker',
        'M.core_formchangechecker.init',
        array(array('formid' => 'responseform')) 
    );

Of course, you do that sort of thing totally at your own risk!

Many thanks again for reporting this - I depend on such feedback, particularly with Moodle 4, which we're not yet running ourselves on any production sites. 

En respuesta a Richard Lobb

Re: Bug: file upload dialog box not showing

por Michael Fairbank -
Richard, Thanks.
By the way, we're currently running Moodle 4.0.4 (build 20220912). CodeRunner is version 5.0.0 (build 2022050100), although we see that's not the latest development version.

We've commented out those lines in our dev environment and it looks like the bug is no longer present, seems like navigating away from the question and coming back work fine too as the state is saved.

We're wondering whether to dare roll this out to our main Moodle environment. What do you think?

Are we going to miss anything useful by having commented out those lines?

If our roll out seems successful, will you be removing those lines from the main development version of CodeRunner?

Thank you!
En respuesta a Michael Fairbank

Re: Bug: file upload dialog box not showing

por Richard Lobb -
Thanks for checking that out Michael - it's reassuring. I'd done a bit of testing myself, too, and all looks good.

Deleting those code lines from your main production server should have negligible risk (though I'm always nervous about making such statements!). Those lines were added as a workaround for an issue/bug in the underlying Moodle code. Without those code lines, if you (as teacher) previewed a question with user-supplied attachments, you got a spurious warning about navigating away with unsaved changes when you clicked the Check button. [Or at least that's what my comment in the source code + very vague memories recall.]

Somewhere around Moodle 3.10/Moodle 3.11 the core question/preview.php code was updated to include those lines (see here) so my patch has been redundant since then anyway.

It seems like the whole approach to form-change checking has been reworked in Moodle 4.0 so my patch is no longer just redundant - it's using deprecated code and causing problems.

I've deleted those lines in my development code on my system and the changes will get pushed in due course.

Thanks again for reporting and helping with the debugging.
En respuesta a Richard Lobb

Re: Bug: file upload dialog box not showing

por Michael Fairbank -
Ok, thanks. That's reassuring.
We're not rushing to make this go live - I'll get back to you if it does reveal any problems, but I don't expect it will. Thank you!