I am trying to create a question where the user needs to create a table. If the user gets the syntax wrong, it correctly displays the error. However, if the user gets the syntax right, I see a 404 error. Any idea what I am doing wrong?
I'm not sure why there's a table called 'demo' in the database, and its contents looks very strange. I see the 'Hint' column of that table contains a couple of URLs. Is this intended? My guess is that somehow sqlite3 is attempting to access those URLs though I've no idea why.
If the student's first task is to create a table, I'd suggest as a starting point that you provide them with a database that doesn't contain any tables. Then work from there.
I do not remember where I got that test file. I initially tried using an empty file, but Moodle would not let me upload that, so I found a file containing just one table. I will have another go at creating a db file with no tables. Alternatively, I may have a go at tweaking the Python to create and use an empty file.
The Hint column is just a text column, so your guess that sqlite3 is trying to access the URLs sounds far-fetched to me.
Let's start over. You say "if the user gets the syntax right, I see a 404 error". It shouldn't be possible to get a 404 error when submitting an answer to a coderunner question, so something very strange is happening. My reason for asking for the exported question was to see if I could replicate the error. However, the question's answer field is empty. So could you tell me what output you enter into the answer box that gives rise to a 404, please?
I'm wondering if your Moodle server uses an old version of PHP and the result table rendering in the non-error case happens to use PHP code that isn't supported on your server. Do other CodeRunner question types work OK, for example a simple Hello world Python question?
I don't suppose you have access to the PHP error log do you? I suspect there might be some interesting messages logged when the question fails. Could a system administrator check the error log if you gave them the exact time of a 404-generating submission?
One simple experiment you could do that might help close in on the problem is the following. Check the 'Customise' checkbox in your question and inspect the template code in the Customisation section. Starting around line 34 you should see code like the following:
with open('commands') as cmd_input: text_input = cmd_input.read() try: output = subprocess.check_output(['sqlite3', db_working], input=text_input, universal_newlines=True) print(output) except Exception as e: raise Exception("sqlite3 error: " + str(e))
If you replace the 'print(output)' line there with the line
raise Exception("Output from run: " + output)does the 404 error go away, giving you instead an extended error message (probably with the output from the run being empty)? [In case you're not a Python programmer, please be aware that the indentation of the replacement line must be exactly the same as the line it replaces, namely 8 spaces.]
If the 404 does go away, put back the original line but modified to
print("Output: " + output)
This is to see if the empty column case is causing the problem.
And yes, I admit I'm still clutching at straws, but hopefully these ones are more plausible?
I do not have access to the PHP error log, although I might be able to get it. I will let you know if it shows up anything interesting.