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

mod_data_get_entries webservice fails when no fields are created

XMLWordPrintable

    • MOODLE_401_STABLE
    • MOODLE_401_STABLE
    • MDL-75353-master
    • Hide

      Covered by PHPUnit tests. 

       

      The scenario reported in the description of this issue could be also tested to confirm it has been fixed (although it's completely optional because it has been also covered with PHPUnit tests).

      [OPTIONAL] Testing scenario

      1. Login as admin.
      2. Create a course.
      3. Enrol the teacher user on the course.
      4. Create an empty database activity.
      5. Go to Site administration > Advanced features and enable "Enable web services for mobile devices".
      6. Go to Site administration > Server > Web services > Manage tokens.
      7. Create a Token in the mobile app service for the teacher user (not an admin account)
      8. Open the console and execute this new curl request, replacing:
        • YOUR_SITE_URL with your Moodle instance URL.
        • WSTOKEN with the token you just created.
        • DATABASEID with the database identifier you've created in the course (if it's a clean instance, it will be 1).

          curl 'http://YOUR_SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_data_get_entries&wstoken=WSTOKEN&databaseid=DATABASEID&returncontents=1' | python -m "json.tool"

      9. Confirm that in the curl request response:
        • There is no exception displayed.
        • Entries is set to [] and listviewcontents is an empty string.
      Show
      Covered by PHPUnit tests.    The scenario reported in the description of this issue could be also tested to confirm it has been fixed (although it's completely optional because it has been also covered with PHPUnit tests). [OPTIONAL] Testing scenario Login as admin. Create a course. Enrol the teacher user on the course. Create an empty database activity. Go to Site administration > Advanced features and enable "Enable web services for mobile devices". Go to Site administration > Server > Web services > Manage tokens. Create a Token in the mobile app service for the teacher user (not an admin account) Open the console and execute this new curl request, replacing: YOUR_SITE_URL with your Moodle instance URL. WSTOKEN with the token you just created. DATABASEID with the database identifier you've created in the course (if it's a clean instance, it will be 1). curl 'http://YOUR_SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_data_get_entries&wstoken=WSTOKEN&databaseid=DATABASEID&returncontents=1' | python -m "json.tool" Confirm that in the curl request response: There is no exception displayed. Entries is set to [] and listviewcontents is an empty string.
    • 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:

      1. Create a database and do not create any field
      2. Call mod_data_external:get_entries (or call mod_data_get_entries webservice) with returncontent param to true
      3. Expected: it returns the entries with the default template (empty in this case because there are no fields to present)
      4. What happens: it returns an exception

      The reason for the error:

      1. The get_template method tries to find the template from the data instance and, if not present, it calls to data_generate_default_template
      2. 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).
      3. The result is that the get_template method calls for a new Template with a null $templatecontent

      How to solve it:

      1. 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).
      2. 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.
      3. Develop a PHPUnit test to test this scenario
      4. Add the changes to the upgrate.txt file.

       

            sarjona Sara Arjona (@sarjona)
            tusefomal Ferran Recio
            Ferran Recio Ferran Recio
            Amaia Anabitarte Amaia Anabitarte
            John Edward Pedregosa John Edward Pedregosa
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 1 hour, 15 minutes
                1d 1h 15m

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