Moodle

Block "Tags" does not work in PSQL: tg.tagtype must appear in the GROUP BY

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9
  • Fix Version/s: 1.9.1
  • Component/s: Blocks
  • Labels:
    None
  • Environment:
    Fresh CVS update of MOODLE_19_STABLE, just several hours old
  • Database:
    PostgreSQL
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

When I add block "Tags" to the homepage, I am getting the following error:

ERROR: column "tg.tagtype" must appear in the GROUP BY clause or be used in an aggregate function

SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag FROM mdl_tag_instance ti INNER JOIN mdl_tag tg ON tg.id = ti.tagid GROUP BY tg.id, tg.rawname, tg.name, tg.flag ORDER BY count DESC, tg.name ASC

  • line 686 of lib/dmllib.php: call to debugging()
  • line 949 of lib/dmllib.php: call to get_recordset_sql()
  • line 27 of tag/locallib.php: call to get_records_sql()
  • line 64 of blocks/tags/block_tags.php: call to tag_print_cloud()
  • line 240 of blocks/moodleblock.class.php: call to block_tags->get_content()
  • line 264 of blocks/moodleblock.class.php: call to block_base->is_empty()
  • line 338 of lib/blocklib.php: call to block_base->_print_block()
  • line 265 of index.php: call to blocks_print_group()

Warning: Invalid argument supplied for foreach() in XXXXXXXXXXXXXX/tag/locallib.php on line 35

Issue Links

Activity

Hide
David Mudrak added a comment -

The fix of GROUP BY is quite easy - the problem is self explaining. The problem with produced warning can be handled by an extra empty() check of get_records_sql() result.

MDL-13791.patch.txt works for me at PostgreSQL 8.1. I haven't tested on MySQL but should be fine as well.

Show
David Mudrak added a comment - The fix of GROUP BY is quite easy - the problem is self explaining. The problem with produced warning can be handled by an extra empty() check of get_records_sql() result. MDL-13791.patch.txt works for me at PostgreSQL 8.1. I haven't tested on MySQL but should be fine as well.
Hide
Martin Dougiamas added a comment -

arg Urgent one for you, Mat!

Show
Martin Dougiamas added a comment - arg Urgent one for you, Mat!
Hide
Mathieu Petit-Clair added a comment -

Fixed a few minutes ago in MDL-13769

Show
Mathieu Petit-Clair added a comment - Fixed a few minutes ago in MDL-13769
Hide
David Mudrak added a comment -

Mathieu, the fix of GROUP BY is ok. However, there is still another problem. get_records_sql() returns false if no records were found or an error occured. Therefore, if there is not tag defined yet, PHP warning is produced:

Warning: Invalid argument supplied for foreach() in XXXXXXXXXXXXXX/tag/locallib.php on line 35

because foreach() can't iterate thru false. See the patch posted by me yesterday:

      • 25,30 ****
      • 25,33 ----
        'FROM '. $CFG->prefix .'tag_instance ti INNER JOIN '. $CFG->prefix .'tag tg ON tg.id = ti.tagid '.
        'GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.tagtype '.
        'ORDER BY count DESC, tg.name ASC', 0, $nr_of_tags);
        + if (empty($tagcloud)) { + $tagcloud = array(); + }

$totaltags = count($tagcloud);
$currenttag = 0;

This should be another issue, sorry for ticket mixing.

Show
David Mudrak added a comment - Mathieu, the fix of GROUP BY is ok. However, there is still another problem. get_records_sql() returns false if no records were found or an error occured. Therefore, if there is not tag defined yet, PHP warning is produced: Warning: Invalid argument supplied for foreach() in XXXXXXXXXXXXXX/tag/locallib.php on line 35 because foreach() can't iterate thru false. See the patch posted by me yesterday:
      • 25,30 ****
      • 25,33 ---- 'FROM '. $CFG->prefix .'tag_instance ti INNER JOIN '. $CFG->prefix .'tag tg ON tg.id = ti.tagid '. 'GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.tagtype '. 'ORDER BY count DESC, tg.name ASC', 0, $nr_of_tags); + if (empty($tagcloud)) { + $tagcloud = array(); + }
$totaltags = count($tagcloud); $currenttag = 0; This should be another issue, sorry for ticket mixing.
Hide
Mathieu Petit-Clair added a comment -

You are perfectly right, it's fixed now. Thanks

Show
Mathieu Petit-Clair added a comment - You are perfectly right, it's fixed now. Thanks

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: