Skip to content

Magento 2.1.0: db fields with mysql default value CURRENT_TIMESTAMP cannot be updated through the EntityManager #5385

Closed
@heldchen

Description

@heldchen

Steps to reproduce

  1. Install Magento from develop branch.
  2. load a CMS Page through $model = $pageRepository->getById(1);
  3. modify the last update timestamp: $model->setUpdateTime('2016-09-01 00:00:00');
  4. save through $pageRepository->save($model);

Expected result

  1. the cms_pagedatabase column update_time of entity 1 contains 2016-09-01 00:00:00

Actual result

  1. the database column "update_time" contains the old value

the reason being in Magento\Framework\EntityManager\Db\UpdateRow:prepareData:

        foreach ($connection->describeTable($metadata->getEntityTable()) as $column) {
            if ($column['DEFAULT'] == 'CURRENT_TIMESTAMP' || $column['IDENTITY']) {
                continue;
            }

as the column update_time has the default value CURRENT_TIMESTAMP, the field is not appended to the $output array.

please note: i'm aware that cms_page.update_time is auto-updated through mysql's "on update" attribute, I'm merely using this existing model as an example that can be easily reproduced without having to write tons of code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.2.xThe issue has been fixed in 2.2 release lineIssue: Format is not validGate 1 Failed. Automatic verification of issue format is failedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releasebug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions