Views and collection list (in group) throws MySQL error

Bug #1749402 reported by Alexander Del Ponte
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
High
Robert Lyon
17.10
Fix Released
High
Unassigned
18.04
Fix Released
High
Robert Lyon
18.10
Fix Released
High
Robert Lyon

Bug Description

If a normal group member tries to visit views and collections of the group, following warning/error is thrown under some conditions which are mentioned below:

SQL:
[WAR] 93 (lib/errors.php:859) Failed to get a recordset: mysqli error: [1452: Cannot add or update a child row: a foreign key constraint fails ("dp-dev-master-ep"."view_rows_columns", CONSTRAINT "viewrowscolu_vie_fk" FOREIGN KEY ("view") REFERENCES "view" ("id"))] in EXECUTE("INSERT INTO "view_rows_columns" ("view", "row", "columns") VALUES ('46', '1', '3')")Command was: INSERT INTO "view_rows_columns" ("view", "row", "columns") VALUES (?, ?, ?) and values was (view:46,row:1,columns:3)

PHP:
Call stack (most recent first):
log_message("Failed to get a recordset: mysqli error: [1452: Ca...", 8, true, true) at /var/www/mahara/master/htdocs/lib/errors.php:95
log_warn("Failed to get a recordset: mysqli error: [1452: Ca...") at /var/www/mahara/master/htdocs/lib/errors.php:859
SQLException->__construct("Failed to get a recordset: mysqli error: [1452: Ca...") at /var/www/mahara/master/htdocs/lib/dml.php:1105
insert_record("view_rows_columns", object(stdClass), false, false) at /var/www/mahara/master/htdocs/lib/dml.php:1192
ensure_record_exists("view_rows_columns", object(stdClass), object(stdClass)) at /var/www/mahara/master/htdocs/lib/view.php:356
View->__construct(0array(size 25)) at /var/www/mahara/master/htdocs/lib/view.php:5581
View::get_extra_view_info(array(size 2), false) at /var/www/mahara/master/htdocs/view/groupviews.php:52

This happens if the group views and collections are readonly to members, a group collection exisits with at least one view inside and in the DB there is no view which has the same id as this collection.

I didn't went too deep inside the code, but it seems that this issue is somehow connected to the bug #1514608.

It further seems that Mahara interprets a collection as a view trying to get/set view related data using a collection id to avoid having no DB entry in table view_rows_columns for this erroneously supposed view so the actually error should be found in functions calling this code areas (get_extra_view_info).

Reproduce error:
Create a group in which views and collections are only editable by others that normal group members.
Create a view and a collection inside this group and assign the view to the collection.
Make sure, that in the DB there are no entries referring to a view which has the same id as the above created collection (e. g. by deleting a possibly existing view with this id inside Mahara).
As a normal group member call the tab views and collection of the group.

Greetings
Alex

Revision history for this message
Robert Lyon (robertl-9) wrote :

The problem here stems from the htdocs/view/groupviews.php file around these lines:

 $data = View::view_search(null, null, (object) array('group' => $group->id), null, $limit, $offset,
                                          true, null, null, false, null, null,
                                          null, null, true);
 $viewdata = $data->data;
 View::get_extra_view_info($viewdata, false);
 View::get_extra_collection_info($viewdata, false, 'collid');

The issue is that $viewdata is an array of both collection and view data so when it gets to

 View::get_extra_view_info($viewdata, false);

it treats the collection 'id' like it is a view 'id' and if the collection has an 'id' that doesn't exist as an 'id' in the view table we get this error

Revision history for this message
Robert Lyon (robertl-9) wrote :

I'll make a patch to fix this

Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "master" branch: https://reviews.mahara.org/8606

Revision history for this message
Kristina Hoeppner (kris-hoeppner) wrote :

Hi Alexander, can you please give https://reviews.mahara.org/8606 a go and see if it resolves your issue?

Changed in mahara:
status: New → In Progress
importance: Undecided → Medium
importance: Medium → High
Revision history for this message
Alexander Del Ponte (delponte) wrote :

Hi Kristina and Robert,

functionally the problem is resolved, the portfolios now are displayed.
So the error is gone but is replaced with a warning now which is no problem, cause in our prod environment warning are supressed.

[WAR] d5 (lib/view.php:5466) Trying to get property of non-object
Call stack (most recent first):

    log_message("Trying to get property of non-object", 8, true, true, "/var/www/mahara/master/htdocs/lib/view.php", 5466) at /var/www/mahara/master/htdocs/lib/errors.php:521
    error(8, "Trying to get property of non-object", "/var/www/mahara/master/htdocs/lib/view.php", 5466, array(size 13)) at /var/www/mahara/master/htdocs/lib/view.php:5466
    View::get_extra_view_info(array(size 4), false) at /var/www/mahara/master/htdocs/view/groupviews.php:52

Thanks and greetings
Alex

Revision history for this message
ma (mafen1) wrote :

This also affects Mahara 17.10

Revision history for this message
Kristina Hoeppner (kris-hoeppner) wrote :

Thanks for your feedback. I added your comment to the review, Alex. If you like, you can log into https://reviews.mahara.org with your Launchpad ID.

Revision history for this message
Robert Lyon (robertl-9) wrote :

Steps to test:

1) Make a group that is 'Open' and is also 'Publicly viewable group'
2) make some pages in the group and add all of them to a collection
3) share the collection to the group and to registered users

4) find the ID of the collection and then make sure there is no view with same ID in database

Visit the group's 'Pages and collections' tab as a logged in user that is not a member of the group

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/8606
Committed: https://git.mahara.org/mahara/mahara/commit/8eb1878c7ede9d966f6998330eb7728c12b4824e
Submitter: Cecilia Vela Gurovic (<email address hidden>)
Branch: master

commit 8eb1878c7ede9d966f6998330eb7728c12b4824e
Author: Robert Lyon <email address hidden>
Date: Fri Mar 9 12:18:24 2018 +1300

Bug 1749402: Avoid trying to get extra view data on a collection id

behatnotneeded

Change-Id: I83659cec81fbfdaaf37842be00cd83cc1e9185cc
Signed-off-by: Robert Lyon <email address hidden>

Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "18.04_STABLE" branch: https://reviews.mahara.org/8691

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Patch for "17.10_STABLE" branch: https://reviews.mahara.org/8692

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/8691
Committed: https://git.mahara.org/mahara/mahara/commit/6452184a8f6f84ec47efa7f7b69ca6769ba515ed
Submitter: Robert Lyon (<email address hidden>)
Branch: 18.04_STABLE

commit 6452184a8f6f84ec47efa7f7b69ca6769ba515ed
Author: Robert Lyon <email address hidden>
Date: Fri Mar 9 12:18:24 2018 +1300

Bug 1749402: Avoid trying to get extra view data on a collection id

behatnotneeded

Change-Id: I83659cec81fbfdaaf37842be00cd83cc1e9185cc
Signed-off-by: Robert Lyon <email address hidden>
(cherry picked from commit 8eb1878c7ede9d966f6998330eb7728c12b4824e)

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/8692
Committed: https://git.mahara.org/mahara/mahara/commit/f278fb96fc8e88f61068bf3dec7a958b9a452f73
Submitter: Robert Lyon (<email address hidden>)
Branch: 17.10_STABLE

commit f278fb96fc8e88f61068bf3dec7a958b9a452f73
Author: Robert Lyon <email address hidden>
Date: Fri Mar 9 12:18:24 2018 +1300

Bug 1749402: Avoid trying to get extra view data on a collection id

behatnotneeded

Change-Id: I83659cec81fbfdaaf37842be00cd83cc1e9185cc
Signed-off-by: Robert Lyon <email address hidden>
(cherry picked from commit 8eb1878c7ede9d966f6998330eb7728c12b4824e)

Revision history for this message
Alexander Del Ponte (delponte) wrote :

Hi Kristina and Robert,

I had a look at the code and the warning is caused by trying to access an object property on an array as the error message implies.

For my issue everything is working fine when supressing the on screen display of warning messages, but I wonder, if the overall functionality of this code part will be given.

When there is an 'id' field in the array, $v['id'] will have a value, but $v->id won't and the loop will just continue with the next item.

However, thank you very much for your fast response and solution - Many greetings
Alex

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.