Skip to content

Indexer - timestamp is passed to DateTime constructor #38411

Open
@mkidon

Description

@mkidon

Preconditions and environment

magento/magento-cloud-metapackage": "2.4.5

I was unable to naturally reproduce this problem. But it seems that problem is that Indexer state is saved and beforeSave method sets “updated” value to timestamp: https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Indexer/Model/Indexer/State.php#L183

After that Magento\Indexer\Model\Indexer->getLatestUpdated() is called and it passes that timestamp to DateTime object constructor: https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Indexer/Model/Indexer.php#L378

This results with “Exception: Failed to parse time string” error

Steps to reproduce

Don't know how to reproduce this. Found these errors in logs, caused by 3rd party module. Best to use code snipped:
`<?php

require 'app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);

function _log($msg)
{
print_r($msg);
print "\n";
}

/** @var \Magento\Framework\ObjectManager\ObjectManager $objectManager */
$objectManager = $bootstrap->getObjectManager();

$dateTime = new \DateTime();
/** @var \Magento\Indexer\Model\Indexer $indexer */
$indexer = $objectManager->get('\Magento\Indexer\Model\Indexer');

$indexer->load('customer_grid');
$indexer->getView()->getState()->setUpdated($dateTime->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
$indexer->getView()->getState()->setMode(\Magento\Framework\Mview\View\StateInterface::MODE_ENABLED);

// NO ERRORS
_log($indexer->getLatestUpdated());

$state = $indexer->getState();
$status = $state->getStatus();
$state->setStatus('test');
$state->setStatus($status);
$state->save();

// ERROR
_log($indexer->getLatestUpdated());`

Expected result

No errors I guess

Screenshot 2024-02-01 211823

Actual result

Exception: Failed to parse time string (1699254906) at position 7 (9): Unexpected character in /vendor/magento/module-indexer/Model/Indexer.php:378
Screenshot 2024-02-01 211755

Additional information

No response

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: FrameworkComponent: IndexerIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: ready for devReported on 2.4.xIndicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions