MantisBT - ATutor
View Issue Details
0003174ATutorTests/Surveyspublic2007-09-06 01:142008-08-21 08:58
IndieRect 
harris 
normalmajoralways
closedfixed 
1.5.5 
1.6 
SVN
0003174: Test results display as "N/A"
Bug description:
If a randomized test has no required questions, editing it (tools/tests/edit_test.php) will assing AT_tests.out_of a zero and consequently cause substitution of any results in the test with "N/A" ? on all student and instructor pages.

Cause:
Function get_total_weight() of /include/lib/test_result_functions.inc.php does not handle appropriately the values returned by SQL queries.
Just trace what would happen if there're no required question, and you'll see.

Solution:
A straightforward fix is replacing lines 18...20 of /include/lib/test_result_functions.inc.php with:

    $sql = "SELECT SUM(weight) AS weight, COUNT(*) AS cnt FROM ".TABLE_PREFIX."tests_questions_assoc WHERE test_id=$tid AND required = '1' GROUP BY required";
    $result = mysql_query($sql, $db);
    $row_required = mysql_fetch_assoc($result);

    $sql = "SELECT SUM(weight) AS weight, COUNT(*) AS cnt FROM ".TABLE_PREFIX."tests_questions_assoc WHERE test_id=$tid AND required = '0' GROUP BY required";
    $result = mysql_query($sql, $db);

BTW, I'm often amazed lately with your usage of clearly unsafe programming techniques, and apparent lack of testing.
No tags attached.
Issue History
2007-09-06 01:14IndieRectNew Issue
2007-09-06 01:14IndieRectAffects version => SVN
2007-12-09 05:44gregNote Added: 0002594
2007-12-11 22:20IndieRectNote Added: 0002618
2007-12-11 22:34IndieRectNote Added: 0002619
2007-12-12 08:12gregStatusnew => assigned
2007-12-12 08:12gregAssigned To => harris
2007-12-13 12:15harrisNote Added: 0002635
2007-12-13 12:15harrisStatusassigned => resolved
2007-12-13 12:15harrisFixed in Version => 1.6
2007-12-13 12:15harrisResolutionopen => fixed
2007-12-13 12:15harrisNote Added: 0002636
2008-08-21 08:58gregStatusresolved => closed

Notes
(0002594)
greg   
2007-12-09 05:44   
Are you still able to reproduce this problem? I can't seem to.

Re: testing, with new blood on the team, testing will improve.

What unsafe technique are you referring to?
(0002618)
IndieRect   
2007-12-11 22:20   
It is still there as of beta 1, just moved to lines 89...91.
Steps to reproduce:
1. Create a randomized test (or use an existing one).
2. Add a few questions.
3. Assign them some weight.
4. None of the questions should be required.
5. Edit the test; the exact changes are not important. The bug creeps right after you click "Save".
6. Take the test.
7. After submission, you'll see that your result is "N/A".

If you compare the DB test entry before and after step 5, you'll see `out_of` field being reset.
(0002619)
IndieRect   
2007-12-11 22:34   
By "unsafe techniques" I meant two things:
1. Insufficient planning, which might be the reason for not foreseeing a case when there are no required questions.
2. Not checking return values of SQL queries.

The first was the cause of at least one major bug - the one which rendered answers to MC questions always wrong (see http://www.atutor.ca/view/3/8595/1.html [^] ).
The second is an ubiquitous practice in the ATutor code, especially for INSERT queries. Changing DB table structure (by you or when tailoring ATutor to some particular site) may cause some INSERT...VALUES queries fail without any notice and hence create hard-to-trace bugs.
(0002635)
harris   
2007-12-13 12:15   
Confirmed.

The first resultset is not guaranteed to be "required".
(0002636)
harris   
2007-12-13 12:15   
Applied IndieRect's suggestion.

7155