-
Bug
-
Resolution: Fixed
-
Minor
-
4.1
-
MOODLE_401_STABLE
-
MOODLE_401_STABLE
-
MDL-75353-master -
-
1
-
HQ Sprint 0.2 Database
Since the code refactor from MDL-75146 the mod_data_get_entries returns an error if the database has no fields created. This scenario does not happen in the web version because it is not used there but it affected the mobile app because it has no zero state and uses this webservice to get the entries.
The steps to reproduce:
- Create a database and do not create any field
- Call mod_data_external:get_entries (or call mod_data_get_entries webservice) with returncontent param to true
- Expected: it returns the entries with the default template (empty in this case because there are no fields to present)
- What happens: it returns an exception
The reason for the error:
- The get_template method tries to find the template from the data instance and, if not present, it calls to data_generate_default_template
- Despite the name, data_generate_default_template has a mixed logic because it does not simple generate the default template but also return false if something goes wrong (instead of throwing an exception) and, if no fields are created, does not return anything (meaning returns a null, which is not even documented).
- The result is that the get_template method calls for a new Template with a null $templatecontent
How to solve it:
- Refactor data_generate_default_template to return always an string (an empty one if no string is available). This is possible because most of the returning false are simply unnecessary checks (they are validating developer errors which should not be possible if the method had strict types).
- Validate all the scenarios in which this method is called and check if it is possible to add a comprehensive throw exception instead of random returning empty values when the method params are wrong.
- Develop a PHPUnit test to test this scenario
- Add the changes to the upgrate.txt file.
- is a regression caused by
-
MDL-75146 Create a new ##id## tag to use in Database activity templates
-
- Closed
-