Changing the indexes of field storage with non revision entity is broken

Created on 31 October 2017, almost 8 years ago
Updated 9 November 2023, almost 2 years ago

Problem/Motivation

SqlContentEntityStorageSchema::updateDedicatedTableSchema() is broken when the entity type doesn't support revision.

The error message is:

TypeError: Argument 4 passed to Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::addIndex() must be of the type array, null given, called in /Project/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php on line 1388 in Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->addIndex() (line 2102 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php).

I use the config_devel to update the field config file automatically. To adding indexes in field table, I add an item indexes into field.storage.registrant.field_my_field.yml. It looks like:

langcode: zh-hant
status: true
dependencies:
  module:
    - rng
id: registrant.field_my_field
field_name: field_my_field
entity_type: registrant
type: string
settings:
  max_length: 255
  is_ascii: false
  case_sensitive: false
module: core
locked: false
cardinality: 1
translatable: true
indexes:
  value:
    - value
persist_with_no_fields: false
custom_storage: false

Set the config file importing automatically in config_devel. I expect config_devel will import the config and add value (field_register_code_value) field as index in field_my_field database table. However, when the index is added or dropped, it will throw an exception as above.

Proposed resolution

Check if the entity type support revision or not.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Field 

Last updated about 1 month ago

Created by

🇹🇼Taiwan johnhuang0808

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

    The change/bugfix cannot be fully demonstrated by automated testing, and thus requires manual testing in a variety of environments.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • 🇧🇪Belgium matthijs

    I can confirm the patch fixes the issue.

  • 🇧🇪Belgium HnLn

    I can also confirm the patch works.

  • 🇬🇧United Kingdom catch

    This is major. Most core entities are revisionable so it doesn't come up often, but the API should work and fatal errors on non-existent tables isn't working.

  • First commit to issue fork.
  • Merge request !12913Resolve #2919927 "Changing the indexes" → (Open) created by achap
  • achap 🇦🇺

    I created a merge request as the patch was still creating the revision table even if its not revisionable. Also removed the comments as suggested. Don't know how to test this one off the top of my head but manually testing of both a non revisionable and revisionable entity successfully added + deleted the indexes.

    Leaving as needs work for tests.

  • Pipeline finished with Failed
    2 months ago
    #564991
Production build 0.71.5 2024