Skip to content

[Bug] Fixes pimcore/platform-version#467: Key the element reference cache by type as well as id - #2032

Open
nobodys-tools wants to merge 1 commit into
pimcore:2026.xfrom
nobodys-tools:fix/reference-resolver-cache-key
Open

[Bug] Fixes pimcore/platform-version#467: Key the element reference cache by type as well as id#2032
nobodys-tools wants to merge 1 commit into
pimcore:2026.xfrom
nobodys-tools:fix/reference-resolver-cache-key

Conversation

@nobodys-tools

@nobodys-tools nobodys-tools commented Sep 10, 2026

Copy link
Copy Markdown

Fixes pimcore/platform-version#467

ReferenceResolver caches resolved references by id alone. Documents, assets and data objects have independent id sequences, so a document and an asset can share one id; whichever is resolved first fills the cache and every later element with that id gets its payload back, whatever type it is.

On an element carrying both an asset property and a document property whose targets share an id, GET /properties/{elementType}/{id} therefore returns the same reference for both, and the wrong reference is written back when the properties are saved. PropertyHydrator and MetadataHydrator both resolve through this service.

The lookup itself is correct - Property::getData() goes through Element\Service::getElementById() with the type - so only the cache key has to carry the type.

Expected Behavior
Each property resolves against its own element type.

Actual Behavior
Both properties return the SAME element, the one resolved first.
In the UI the wrong reference is displayed.

The stored data is correct throughout, the Properties table keeps
type=document/data=4 and the frontend resolves it correctly.
Only Studio's representation in Properties table is wrong, and saving from that state writes the wrong value back.

Steps to reproduce

  1. Find a numeric id that exists as both a document (in my case a snippet) and an asset (a folder in my case).
    On a fresh install this is common - e.g. document 4 and asset 4 both exist.
  2. On any element (here: the root document, id 1) add two properties:
    propAsset - type Asset -> the asset with id 4
    propDoc - type Document -> the document with id 4
    Note that "propAsset" sorts before "propDoc".
  3. Save.
  4. Open the element's Properties tab

ReferenceResolver caches resolved references by id alone. Documents, assets
and data objects have independent id sequences, so a document and an asset can
share one id; whichever is resolved first fills the cache and every later
element with that id gets its payload back, whatever type it is.

On an element carrying both an asset property and a document property whose
targets share an id, GET /properties/{elementType}/{id} therefore returns the
same reference for both, and the wrong reference is written back when the
properties are saved. PropertyHydrator and MetadataHydrator both resolve
through this service.

The lookup itself is correct - Property::getData() goes through
Element\Service::getElementById() with the type - so only the cache key has to
carry the type.
Copilot AI balanced review requested due to automatic review settings September 10, 2026 13:37
@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@nobodys-tools

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@nobodys-tools

Copy link
Copy Markdown
Author

recheck

@sonarqubecloud

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.

🟡 Changes recommended

The root-cause fix is sound, but lacks a regression test covering same-ID references across element types.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes cross-type reference cache collisions by keying entries with the element class and ID.

Changes:

  • Uses class-plus-ID cache keys at ReferenceResolver.php:43,58.
  • Correctly covers both direct and resolveData() callers without API changes.
  • A focused regression test is still missing.
File summaries
File Description
src/Resolver/Element/ReferenceResolver.php Prevents assets, documents, and data objects sharing IDs from colliding in the cache.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

{
if (isset($this->cache[$element->getId()])) {
return $this->cache[$element->getId()];
$cacheKey = $element::class . '_' . $element->getId();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Not adding a unit test here. The change is a cache-key correction with no behaviour of its own to assert beyond the collision itself, and the fix was verified against a real installation

@nobodys-tools nobodys-tools changed the title [Bug]: Key the element reference cache by type as well as id [Bug] Fixes pimcore/platform-version#467: Key the element reference cache by type as well as id Sep 10, 2026
@nobodys-tools
nobodys-tools marked this pull request as ready for review September 10, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Studio: element references resolve to the wrong element when a document, asset or object share the same numeric id

2 participants