-
Bug
-
Resolution: Fixed
-
Minor
-
4.0.6, 4.1.1
-
MOODLE_400_STABLE, MOODLE_401_STABLE
-
MOODLE_400_STABLE, MOODLE_401_STABLE
-
MDL-77321-401 -
- Covered by CI (PHPUnit)
-
WP Sprint 2023-I1.2 (Paul)
We hit this problem on Workplace but I think I can find examples in LMS as well.
There are some rare cases when the report definition depends on the current user. In case of Workplace, we add a tenant subquery to the "User list" datasource, for example so the same report for different users has different SQL and produces different results.
When we create a schedule for such report, the datasource definition is created for the first user in the batch and then re-used for all other users, even if the schedule setting is to generate a new report for each user.
As a very simple solution I can suggest to add a user id in the cache key. I'll try to come up with some testing instructions or unittests for this in LMS.
diff --git a/reportbuilder/classes/manager.php b/reportbuilder/classes/manager.php
|
index 143a7cd20ef..cebfa5b775d 100644
|
--- a/reportbuilder/classes/manager.php
|
+++ b/reportbuilder/classes/manager.php
|
@@ -50,7 +50,8 @@ class manager {
|
* @throws source_unavailable_exception
|
*/
|
public static function get_report_from_persistent(report $report, array $parameters = []): base {
|
- $instancekey = $report->get('id');
|
+ global $USER;
|
+ $instancekey = $report->get('id') . ':' . $USER->id;
|
if (!array_key_exists($instancekey, static::$instances)) {
|
$source = $report->get('source');
|
|
|