Fix indexer state updated value not being parsable as a datetime (#38411)#40979
Open
lbajsarowicz wants to merge 2 commits into
Open
Fix indexer state updated value not being parsable as a datetime (#38411)#40979lbajsarowicz wants to merge 2 commits into
lbajsarowicz wants to merge 2 commits into
Conversation
Indexer\Model\Indexer\State and Mview\View\State stored `updated` as a raw Unix timestamp via time(). Indexer::getLatestUpdated() feeds that value into new \DateTime(), which throws "Failed to parse time string" when the state is read from memory before being reloaded from the DB. Store the value pre-formatted as Y-m-d H:i:s, identical to what the DB adapter already persists, so in-memory reads stay parsable. Fixes magento#38411
|
Hi @lbajsarowicz. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
Contributor
Author
|
@magento run all tests |
Contributor
Author
|
@magento run all tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description (*)
Magento\Indexer\Model\Indexer\State::beforeSave()andMagento\Indexer\Model\Mview\View\State::beforeSave()set theupdatedfield to a raw Unix timestamp via
time():The
updatedcolumn is adatetime, and the DB adapter formats the integeron INSERT, so the persisted value is correct. However, the in-memory model
retains the raw integer after saving (Magento does not reload the entity after
save()).Magento\Indexer\Model\Indexer::getLatestUpdated()then feeds that valuestraight into a
\DateTimeconstructor:When the state has been saved but not reloaded within the same request (e.g. by
third-party code, observers, or ESI blocks),
getUpdated()returns the rawinteger, and
new \DateTime("1783697110")throws:Fix
Store the value pre-formatted as
Y-m-d H:i:sin bothbeforeSave()methods —identical to what the DB adapter already persists — so the in-memory value is
consistent with the persisted one and remains parsable by
\DateTime:The persisted DB value is unchanged; only the in-memory representation is
corrected.
Related Pull Requests
None
Fixed Issues (*)
Fixes #38411
Manual testing scenarios (*)
the database), e.g.:
getLatestUpdated()throwsFailed to parse time string.getLatestUpdated()returns a valid datetime string withno exception.
Questions or comments
The persisted database values are unaffected — the DB adapter already stored the
adapter-formatted datetime. This change only aligns the in-memory value with the
persisted one.
Contribution checklist (*)
for both
Statemodels)