Problem/Motivation

I'll add more later and add a patch later when I get a chance.

When using the openai_devel to generate some Articles, the default content type with the default install, I would get this error
array_rand(): Argument #1 ($array) must be of type array, null given and could not generate any content.

I don't have the full error message because my local isn't running, but it pointed to /openai_devel/src/Plugin/DevelGenerate/ContentGPTDevelGenerate.php Line 223 which is $node_type = array_rand($results['node_types']);.

Doing some step debugging I saw that $results['node_types'] was not always an array and array_rand() is causing the error because $results['node_types'] is a string and not an array.

Steps to reproduce

  1. Default install and enable openai_devel
  2. Enable pathauto
  3. Enter your openai key and id in config
  4. Try generating a couple of Articles (only Articles) entering body as a field, select generate path and select a user

Proposed resolution

Check that $results['node_types'] is an array before using array_rand().

    if (is_array($results['node_types'])) {
      $node_type = array_rand($results['node_types']);
    }
    else {
      $node_type = $results['node_types'];
    }

Step debugging was ery slow because the API calls to OpenAI took a long time. I suppose there could be another reason that $results['node_types'] is not always an array but sometimes a string.

Remaining tasks

User interface changes

API changes

Issue fork openai-3404107

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kamkejj created an issue. See original summary.

kamkejj’s picture

Issue summary: View changes
abhishek_gupta1’s picture

Status: Active » Needs review

I verified this issue on my local, not getting above error. working fine for me.

kevinquillen’s picture

  • kevinquillen committed 99c31e35 on 1.0.x authored by kamkejj
    Issue #3404107 by kamkejj, kevinquillen: array_rand(): Argument #1 ($...
kevinquillen’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.