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

Creating AI provider instances broken with default/absent config

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 5.0
    • 5.0
    • AI

      See the following method parameter added in MDL-82977

      public function create_provider_instance(
          ...
          ?array $config = null,
      ): provider {
      

      The problem is you cannot omit the parameter (despite the contract stating it's optional) because if null value is passed we get the following error:

      There were 4 errors:
       
      1) aiprovider_openai\provider_test::test_get_action_list
      TypeError: Cannot assign null to property core_ai\provider::$config of type array
       
      /mnt/export/moodle/master/src/ai/classes/provider.php:61
      /mnt/export/moodle/master/src/ai/classes/manager.php:380
      /mnt/export/moodle/master/src/ai/provider/openai/tests/provider_test.php:45
      

      We also cannot pass an empty array, because if we do that they we get the same error again:

      There were 4 errors:
       
      1) aiprovider_openai\provider_test::test_get_action_list
      TypeError: Cannot assign null to property core_ai\provider::$config of type array
       
      /mnt/export/moodle/master/src/ai/classes/provider.php:61
      /mnt/export/moodle/master/src/ai/classes/manager.php:380
      /mnt/export/moodle/master/src/ai/provider/openai/tests/provider_test.php:45
      

      The problem is this line of the change because subsequent methods in the callstack always assume that value is a JSON encoded array. Fix that, tighten up the contract and remove this element of surprise for developers

      I suspect this is why the unit tests that is never asserted. Looks like a code smell just to workaround this bug

      Found this while writing some unit tests for an AI provider during project week

            pholden Paul Holden
            pholden Paul Holden
            David Carrillo David Carrillo
            Huong Nguyen Huong Nguyen
            CiBoT CiBoT
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 35 minutes
                35m

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