Latest dev build gives haystack error

Created on 14 September 2024, 6 days ago
Updated 17 September 2024, 4 days ago

After updating to the latest dev build, attempting to translate a piece of content gave an error:
The website encountered an unexpected error. Try again later.

If I inspect the recent logs, I see the following error:
TypeError: array_search(): Argument #2 ($haystack) must be of type array, null given in array_search() (line 191 of /home/customer/www/kobejet.com/web/modules/contrib/ai/modules/ai_translate/src/Plugin/FieldTextExtractor/ReferenceFieldExtractor.php).

Adding a null check before calling array_search() appears to prevent this error in this case, but I'm unsure if this is the proper fix. I modified the end of the ReferenceFieldExtractor.php file at /modules/contrib/ai/modules/ai_translate/src/Plugin/FieldTextExtractor/ReferenceFieldExtractor.php to:

  /**
   * Get default AI translatability for an entity type.
   *
   * @param string $entityTypeId
   *   Entity type ID.
   *
   * @return bool
   *   TRUE to translate referenced entities of this type by default.
   */
  protected function entityTypeTranslatedDefault(string $entityTypeId) : bool {
    $defaults = $this->config->get('reference_defaults', []);

    // Ensure that $defaults is an array before passing it to array_search.
    if (is_array($defaults)) {
      return (array_search($entityTypeId, $defaults) !== FALSE);
    }

    // Default is to not translate entities of unknown type if $defaults is not an array.
    return FALSE;
  }
πŸ› Bug report
Status

Fixed

Version

1.0

Component

Other Submodules

Created by

πŸ‡ΊπŸ‡ΈUnited States W01F

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

Comments & Activities

  • Issue created by @W01F
  • πŸ‡©πŸ‡ͺGermany Marcus_Johansson

    I will look into this tomorrow, but before I do that, did you run the update? `drush updb` or visit update.php.

  • πŸ‡©πŸ‡ͺGermany Marcus_Johansson

    @w01f The only thing I can think about based on the code, is that you didn't run the update command/update file after updating. Could you try that and see if it works?

  • πŸ‡ΊπŸ‡ΈUnited States W01F

    I did run updb and it still showed the WSOD error when attempting to AI translate.

    I just updated from dev-1.0.x 3c91124 => dev-1.0.x 0aca34b and discarded my changes, and tried again, but hit the same WSOD.

    I made the same modification as outlined above and once again it's working correctly.

  • πŸ‡©πŸ‡ͺGermany Marcus_Johansson

    Ah, got it - I missunderstood the issue and thought the prompt was missing. I will ping in valthebald and see if he can have a look. I'm trying to figure out though how it got into a state on settings that value to NULL.

    I'm think your system will work if you go in and fill in the translation settings (admin/config/ai/ai_translate), but it should also work with NULL.

    I will check with valdthebald, how the system should work there, but since the config says _fallback is TRUE, I think we should set the unknown to TRUE.

  • Status changed to Needs review 4 days ago
  • πŸ‡©πŸ‡ͺGermany Marcus_Johansson

    I discussed it with @valthebald and it was just the default array not being set correctly. I've pushed this change, see if that helps w01f.

    You can try it directly on the 1.0.x-dev branch.

  • πŸ‡ΊπŸ‡ΈUnited States W01F

    @marcus_johansson, just updated and tested the latest dev build - looks fixed!

  • Status changed to Fixed 4 days ago
Production build 0.71.5 2024