Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fieldspec Enum(["value1","value2"]) does not work #10435

Closed
ntd opened this issue Aug 3, 2022 · 2 comments
Closed

Fieldspec Enum(["value1","value2"]) does not work #10435

ntd opened this issue Aug 3, 2022 · 2 comments

Comments

@ntd
Copy link
Contributor

ntd commented Aug 3, 2022

Present in Silverstripe 4.9 and 4.11: see this forum thread for a real world example of this issue.

Defining a field with the above spec throws the following error:

[Emergency] Uncaught SilverStripe\ORM\Connect\DatabaseException: Couldn't run query: ALTER TABLE ... ADD ... enum() 

The same fieldspec in different formats works fine:

static private $db = [
    `throw-error` => 'Enum(["Value1", "Value2"])',
    'works'       => 'Enum(array("Value1", "Value2"))',
    'also-works'  => 'Enum("Value2, Value2")',
];

After investigating, it seems the array part in the first syntax is stripped away by the following code in DBSchemaManager.php

                //Is this an array field?
                $arrayValue = '';
                if (strpos($fieldSpec ?? '', '[') !== false) {
                    //If so, remove it and store that info separately
                    $pos = strpos($fieldSpec ?? '', '[');
                    $arrayValue = substr($fieldSpec ?? '', $pos ?? 0);
                    $fieldSpec = substr($fieldSpec ?? '', 0, $pos);
                }

                /** @var DBField $fieldObj */
                $fieldObj = Injector::inst()->create($fieldSpec, $fieldName);
                $fieldObj->setArrayValue($arrayValue);

No idea what that $arrayValue is used for, but after removing the if branch dev/build succeeded.

PRs

erikfrerejean added a commit to wedevelopnl/silverstripe-elemental-list-items that referenced this issue Dec 16, 2022
There seem to be a bug with Enum array parsing in the framework silverstripe/silverstripe-framework#10435, as a precaution switch to a notation that doesn't break by this issue.
@xini
Copy link
Contributor

xini commented Jun 23, 2023

also see silverstripe/developer-docs#288

@GuySartorelli
Copy link
Member

PR merged. It'll be tagged automatically as 4.13.12 once the merge CI is green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants