Skip to content

Serialization issue when copying AlterTableCommand #29

@krystof018

Description

@krystof018

Hello, I came across bug when creating new instance of AlterTableCommand from old one.

$actions = getMeNewActions($originalCommand);

 $newCommand = new AlterTableCommand(
    $originalCommand->getTable(),
    $actions,
    $originalCommand->getAlterOptions(),
    $originalCommand->getOptionsList(), // this causes the problem
    $originalCommand->getPartitioning(),
);

Problem is with AlterTableCommand::getOptionsList().

public function getOptionsList(): TableOptionsList
{
    return $this->tableOptions ?? new TableOptionsList([]);
}

This would not be problematic itself if serialization of AlterTableCommand did not depend on null check:

// in AlterTableCommand::serialize() line 127
if ($this->tableOptions !== null) {
    if (!$this->actions->isEmpty()) {
        $result .= ',';
    }
    $result .= "\n" . $formatter->indent . $this->tableOptions->serialize($formatter, ",\n", ' ');
}

The logic should probably check if the TableOptionsList is empty so the comma + \n + indent there is not added without reason since empty TableOptionsList serializes to ''.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions