SqlContentEntityStorageSchema creates an invalid schema if multiple entity keys point to the same field

Created on 20 January 2017, over 8 years ago
Updated 8 September 2025, 9 days ago

Given a content entity with the following keys:

 *   entity_keys = {
 *     "id" = "uuid",
 *     "label" = "name",
 *     "uuid" = "uuid",
 *   },

When SqlContentEntityStorageSchema::getEntitySchema() generates the schema SQL query, it will get the uuid field twice in in inner foreach loop, here:

         foreach ($table_mapping->getFieldNames($table_name) as $field_name) {
          if (!isset($storage_definitions[$field_name])) {
            throw new FieldException("Field storage definition for '$field_name' could not be found.");
          }
          // Add the schema for base field definitions.
          elseif ($table_mapping->allowsSharedTableStorage($storage_definitions[$field_name])) {
            $column_names = $table_mapping->getColumnNames($field_name);
            $storage_definition = $storage_definitions[$field_name];
            $schema[$table_name] = array_merge_recursive($schema[$table_name], $this->getSharedTableFieldSchema($storage_definition, $table_name, $column_names));
          }
        }

Because of how array_merge_recursive() works, in the schema of the uuid field, the type key will contain an array of two identical items, instead of the proper column type. This causes the type from the generated SQL to be omitted, like this:

CREATE TABLE {foobar} (
`uuid`  NOT NULL,
πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

entity system

Created by

πŸ‡­πŸ‡ΊHungary tamasd

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

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

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

    Thank you for reporting this problem. We rely on issue reports like this one to resolve bugs and improve Drupal core.

    Since there has been no activity here for over 8 years we are asking if this problem persists on a currently supported version of Drupal. To help, add a comment explaining if the problem still occurs or not. Any extra detail you can provide can help others who experienced this.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
    Thanks!

Production build 0.71.5 2024