Active
Project:
Drupal core
Version:
main
Component:
entity system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
19 Jul 2021 at 11:03 UTC
Updated:
2 Sep 2026 at 09:12 UTC
Jump to comment: Most recent
I've the following definition,
$fields['type'] = BaseFieldDefinition::create('list_string')
->setLabel(t('Type'))
->setDescription(t('The type of receiver'))
->setSettings([
'max_length' => 16,
'allowed_values' => [
'email' => 'email',
'mobile' => 'mobile',
],
]);
$fields['receiver'] = BaseFieldDefinition::create('string')
->setLabel(t('Receiver'))
->setDescription(t('The email/phone to receive the OTP.'))
->setSettings([
'max_length' => 192,
'text_processing' => 0,
]);
$fields['is_verified'] = BaseFieldDefinition::create('list_string')
->setLabel(t('Is Verified'))
->setDescription(t('Whether the OTP been verified or not'))
->setDefaultValue('pending')
->setSettings([
'max_length' => 16,
'allowed_values' => [
'pending' => 'pending',
'yes' => 'yes',
'no' => 'no'
],
]);
Both BaseFieldDefinition::create('list_string') and BaseFieldDefinition::create('string') under the hood are using varchar(255) by default. While 'string' respects the 'max_length', the 'list_string' seems not taking that into account.
I'm hitting the InnoDB table limit while trying the index some columns. I guess the indexing would be successful if I could set optimal length for them.
Comments
Comment #2
sivaji_ganesh_jojodae commentedComment #9
kristiaanvandeneyndeI was just bitten by this too, trying to add an index on a list_string field (among other fields) and noticing nothing out of the ordinary. Only when looking deeper did I notice Drupal had reduced the field's index length to 191, essentially making the index do nothing. Even worse, because the index now exists and cannot really help, the overall outcome is slower than if I had not tried to set an index at all.
Manually changing the field's database column size to something smaller fixes things. But I agree that this should be read from max_length instead of hard-coded to 255.
Edit: Since we now require MySQL 5.7+ for Drupal, I wonder how relevant Schema::getNormalizedIndexes() still is.
Comment #10
kristiaanvandeneyndeDid some digging and found this CR: https://www.drupal.org/node/2510940
That indicates you can use max_length and is_ascii to manipulate the schema of a StringItem, which is true. Seems like ListStringItem was overlooked?
Comment #11
kristiaanvandeneyndeComment #12
kristiaanvandeneyndeOpened #3620372: MySQL Schema::getNormalizedIndexes() still assumes old, unsupported databases for the thing Drupal does to indexes, and then maybe this issue can be repurposed for allowing ListStringItem to also have the settings that can manipulate the schema.