Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-74175

Cohort report source category column can throw exceptions during aggregation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 4.0
    • 4.0
    • Report builder
    • MOODLE_400_STABLE
    • MOODLE_400_STABLE
    • Hide
      1. Log in as admin
      2. Navigate to Users > Accounts > Cohorts in site administration
      3. Create two cohorts in system context
      4. Navigate to Courses > Manage courses and categories in site administration
      5. For Category 1 (or any other) click Actions menu > Cohorts
      6. Create two cohorts in the category
      7. Navigate to Reports > Report builder > Custom reports in site administration
      8. Create a new report from Cohorts report source
        • Ensure Include default setup is unchecked
      9. In the report editor, add the Cohort > Category column
      10. Click Aggregate column 'Category' and open the select element
      11. Confirm only the following options are present:
        • Comma separated distinct values
        • Comma separated values
        • Count
        • Count distinct
      12. Change column aggregation to Comma separated distinct values
      13. Confirm column content shows "System, Category 1"
      14. Change column aggregation to Comma separated values
      15. Confirm column content shows "System, System, Category 1, Category 1"
      16. Change column aggregation to Count
      17. Confirm column content shows "4"
      18. Change column aggregation to Count distinct
      19. Confirm column content shows "2"
      Show
      Log in as admin Navigate to Users > Accounts > Cohorts in site administration Create two cohorts in system context Navigate to Courses > Manage courses and categories in site administration For Category 1 (or any other) click Actions menu > Cohorts Create two cohorts in the category Navigate to Reports > Report builder > Custom reports in site administration Create a new report from Cohorts report source Ensure Include default setup is unchecked In the report editor, add the Cohort > Category column Click Aggregate column 'Category' and open the select element Confirm only the following options are present: Comma separated distinct values Comma separated values Count Count distinct Change column aggregation to Comma separated distinct values Confirm column content shows "System, Category 1" Change column aggregation to Comma separated values Confirm column content shows "System, System, Category 1, Category 1" Change column aggregation to Count Confirm column content shows "4" Change column aggregation to Count distinct Confirm column content shows "2"

      The Cohort > Category column within the Cohorts report source is incorrectly defined as TYPE_INTEGER despite returning textual data, which leads to aggregation options showing nonsensical numeric types:

      The second problem is the typing of the callback parameter, which isn't preserved when aggregating with Comma separated [distinct] values types (for context, see this change). This leads to the following due to all classes declaring strict_types=1:

      Exception - Argument 1 passed to core_cohort\local\entities\cohort::core_cohort\local\entities\{closure}() must be of the type int, string given, called in [dirroot]/reportbuilder/classes/local/aggregation/base.php on line 134
      File: ...s/local/entities/cohort.php
      Line: 100
      Stack trace:
       
      Error code: generalexceptionmessage
      * line 100 of /cohort/classes/local/entities/cohort.php: TypeError thrown
      * line 134 of /reportbuilder/classes/local/aggregation/base.php: call to core_cohort\local\entities\cohort::core_cohort\local\entities\{closure}()
      * line 130 of /reportbuilder/classes/local/aggregation/groupconcat.php: call to core_reportbuilder\local\aggregation\base::format_value()
      * line 680 of /reportbuilder/classes/local/report/column.php: call to core_reportbuilder\local\aggregation\groupconcat::format_value()
      * line 201 of /reportbuilder/classes/table/custom_report_table.php: call to core_reportbuilder\local\report\column->format_value()
      * line 2009 of /lib/tablelib.php: call to core_reportbuilder\table\custom_report_table->format_row()
      * line 2133 of /lib/tablelib.php: call to table_sql->build_table()
      * line 262 of /lib/table/classes/external/dynamic/get.php: call to table_sql->out()
      * line 261 of /lib/externallib.php: call to core_table\external\dynamic\get::execute()
      * line 81 of /lib/ajax/service.php: call to external_api::call_external_function()
      

      Found while working on auto-detecting these kind of errors in MDL-73938

        1. Screenshot from 2022-03-11 10-56-17.png
          20 kB
          Paul Holden
        2. Screenshot from 2022-03-11 10-58-05.png
          112 kB
          Paul Holden
        3. MDL-74175 testing.webm
          402 kB
          Angelia Dela Cruz

            pholden Paul Holden
            pholden Paul Holden
            David Carrillo David Carrillo
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Angelia Dela Cruz Angelia Dela Cruz
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 55 minutes
                55m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.