Repository navigation
[Bug] Fall back to the element when its version data cannot be loaded - #2088
Merged
Merged
Conversation
ElementProviderTrait::getVersionData() declares an ElementInterface return type but returned Version::getData() as is. When the version file is missing or unreadable, Version::loadData() returns null, which caused a TypeError in every caller (document/data object/property/workflow/ layout/preview/update services). Fall back to the given element when the version data is not an element. Fixes pimcore/platform-version#526 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Contributor
There was a problem hiding this comment.
🟢 Approved
The shared-boundary fix addresses the root cause and includes focused regression coverage without changing the API contract.
0 open findings
What changed in this PR
Fixes failures when the latest version data is unavailable by falling back to the persisted element.
Changes:
- Validates version data at the shared trait boundary (
ElementProviderTrait.php:87-93), covering every existing caller without changing signatures. - Adds focused regression tests for absent, readable, and unreadable versions (
ElementProviderTraitTest.php:30-59). - No backward-compatibility or documentation impact identified; test execution was not independently verified.
| File | Description |
|---|---|
src/Util/Trait/ElementProviderTrait.php |
Falls back when version data is not an element. |
tests/Unit/Util/Trait/ElementProviderTraitTest.php |
Tests version-data resolution and fallback behavior. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.



Problem
Opening an element whose latest version can't be loaded (version file missing or unreadable) fails with a 500:
Root cause
ElementProviderTrait::getVersionData()declares a non-nullableElementInterfacereturn but returns$version->getData()directly, which isnullwhen the version's data can't be loaded.Fix
Fall back to the element itself (the same thing the method already does when there is no newer version) when the version data isn't an
ElementInterface. Method signature unchanged. This fixes every caller that loads the "latest version" (data object/document detail, layout, properties, search preview, update, workflow details).Tests
tests/Unit/Util/Trait/ElementProviderTraitTest.php: no version, a readable version, and a version whose storage returns nothing. The last case fails on2026.3with the TypeError above and passes with the fix.Not changed here:
VersionRepository::getElementFromVersion()andUpdateControlleralso pass a possibly-null$version->getData()on; there the right answer is probably a 404, which is a separate change.Heads-up @markus-moser: draft #1991 (2026.x) reworks this area — the forward-merge of this fix to 2026.x will touch the same method.
Fixes pimcore/platform-version#526
🤖 Generated with Claude Code