The hook update for add columns doesn't considering short names for dedicated tables

Created on 13 January 2021, about 4 years ago
Updated 15 February 2025, about 2 months ago

Problem/Motivation

The function used to add a new column in hook update (tablefield_add_new_column) doesn't consider short names for dedicated tables. Ex: paragraph_r__6e968f2e7b

Steps to reproduce

  • Install the TableField module with a version before 8.x-2.0-alpha3
  • Create a new tablefield field inside a Paragraph, with the machine name for that field using the max character length (32)
  • Create a new field inside a content type that references that paragraph
  • Create a content of that content type
  • Update the TableField module to the newest version
  • Run the database update (drush updb)
  • Edit or create a content with the field created before
  • Change or fill any field of tablefield
  • Save

It throws the error:

Drupal\Core\Entity\EntityStorageException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_a_big_name_for_tablefields_caption' in 'field list': INSERT INTO {paragraph_r__29be88a9dd} (entity_id, revision_id, bundle, delta, langcode, field_a_big_name_for_tablefields_value, field_a_big_name_for_tablefields_format, field_a_big_name_for_tablefields_caption) 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); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => 5 [:db_insert_placeholder_2] => test_paragraph [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => en [:db_insert_placeholder_5] => a:6:{i:0;a:5:{i:0;s:1:"a";i:1;s:1:"b";i:2;s:1:"c";i:3;s:0:"";i:4;s:0:"";}i:1;a:5:{i:0;s:1:"d";i:1;s:1:"e";i:2;s:1:"6";i:3;s:1:"7";i:4;s:0:"";}i:2;a:5:{i:0;s:0:"";i:1;s:0:"";i:2;s:0:"";i:3;s:0:"";i:4;s:0:"";}i:3;a:5:{i:0;s:0:"";i:1;s:0:"";i:2;s:0:"";i:3;s:0:"";i:4;s:0:"";}i:4;a:5:{i:0;s:0:"";i:1;s:0:"";i:2;s:0:"";i:3;s:0:"";i:4;s:0:"";}s:7:"caption";s:2:"tc";} [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => tc ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 846 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Proposed resolution

Update the tablefield_add_new_column function of tablefield.install to check the table name length. If the name is longer than 48 characters, get the short name generated for the dedicated table. Also, add a new hook update to add the caption field again, in cases where the previous one has already been applied.

I'm already working on the proposed solution.

๐Ÿ› Bug report
Status

Needs work

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024