Problem/Motivation

When inserting an asset from Acquia DAM into a Drupal node using the "Add or select media" modal, the operation fails with a SQLSTATE[22001]: String data, right truncated error if the asset's alt text exceeds the maximum length supported by the acquia_dam_managed_image_alt database column (varchar(512)).

This happens because assets in DAM can have very long alt text values (e.g., keyword-rich metadata strings), and the current string field type with max_length: 512 imposes a hard database-level ceiling that DAM-sourced alt text can easily exceed.

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'acquia_dam_managed_image_alt' at row 1: INSERT INTO "media__acquia_dam_managed_image" ("entity_id", "revision_id", "bundle", "delta", "langcode", "acquia_dam_managed_image_target_id", "acquia_dam_managed_image_alt", "acquia_dam_managed_image_title", "acquia_dam_managed_image_width", "acquia_dam_managed_image_height") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9)
in Drupal\Core\Entity\Sql\SqlContentEntityStorage->saveToDedicatedTables() (line 1400 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Steps to reproduce

  1. Install the acquia_dam module (version 1.1.15) on Drupal.
  2. Configure the integration with an Acquia DAM account containing assets whose alt text field holds a string longer than 512 characters.
  3. Create or edit a node and insert such an asset via the Acquia DAM media selector.
  4. Observe the SQLSTATE[22001] SQL error triggered when attempting to save the media entity.

Proposed resolution

Change acquia_dam_alt_text from a string field (hard-capped at max_length: 512) to a string_long field (unbounded TEXT column). This removes the DB-level length ceiling that DAM-sourced alt text can exceed.

Code changeImageAltTextField::bundleFieldDefinition():

private static function bundleFieldDefinition(): BundleFieldDefinition {
  return BundleFieldDefinition::create('string_long')
    ->setProvider('acquia_dam')
    ->setName(self::IMAGE_ALT_TEXT_FIELD_NAME)
    ->setLabel(new TranslatableMarkup('Alt text'));
}

(max_length setting is dropped, as string_long doesn't support it — the column becomes TEXT.)

Migration for existing sites via hook_update_N():

  1. Directly alter the underlying database column(s) for acquia_dam_alt_text from varchar(512) to TEXT via the schema API ($connection->schema()->changeField()), covering both the dedicated field table and the revision table.
  2. Update Drupal's stored field storage definition record so it matches the new string_long definition and future drush entity:updates runs don't report a mismatch.

Because varcharTEXT is a widening, compatible conversion, existing alt text data is preserved with no truncation or loss.

Issue fork acquia_dam-3611070

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:

Comments

rajeshreeputra created an issue. See original summary.

rajeshreeputra’s picture

Issue summary: View changes

rajeshreeputra’s picture

Status: Active » Needs review

Requesting review.

rajeshreeputra’s picture

Status: Needs review » Fixed

MR merged!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.