Skip to content

[Bug] Fall back to the element when its version data cannot be loaded - #2088

Merged
kingjia90 merged 1 commit into
2026.3from
fix/526-version-data-null
Oct 9, 2026
Merged

kingjia90 merged 1 commit into
2026.3from
fix/526-version-data-null

Conversation

@kingjia90

Copy link
Copy Markdown
Contributor

Problem

Opening an element whose latest version can't be loaded (version file missing or unreadable) fails with a 500:

getVersionData(): Return value must be of type Pimcore\Model\Element\ElementInterface, null returned

Root cause

ElementProviderTrait::getVersionData() declares a non-nullable ElementInterface return but returns $version->getData() directly, which is null when 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 on 2026.3 with the TypeError above and passes with the fix.

Not changed here: VersionRepository::getElementFromVersion() and UpdateController also 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

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>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 11:40
@kingjia90 kingjia90 self-assigned this Oct 9, 2026
@kingjia90 kingjia90 added this to the 2026.3.2 milestone Oct 9, 2026
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

@kingjia90
kingjia90 merged commit 70ebb31 into 2026.3 Oct 9, 2026
21 of 22 checks passed
@kingjia90
kingjia90 deleted the fix/526-version-data-null branch October 9, 2026 12:22
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants