Unnecessary validation error

Created on 26 November 2024, 2 months ago

Problem/Motivation

The OpenAiConfigForm::validate() method contains validation that the "api_key" value has been set to a valid key in a repository. However, the code that checks this calls:

   $api_key = $this->keyRepository->getKey($key)->getKeyValue();

$this->keyRepository->getKey($key) returns NULL if the key repository does not exist, so in cases where the $key value is not set you generate an uncaught fatal error instead of a validation failure.

Steps to reproduce

Add the module to a site.
Save the configuration form without selecting a valid key.

Proposed resolution

If this validation is useful, then the code should be altered so that the fatal error is not generated. As the api_key value is required, it should also be set to required in the form: doing this would prevent submission with an invalid api_key value so the additional check within the validation may not be required anyway.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom MrDaleSmith

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024