mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Embed SPL object ID sometimes seems to change when second level cache is active #7269
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @KDederichs on GitHub (Dec 1, 2023).
Bug Report
Summary
I'm building a multi tenant application based on Api-Platform and after enabling second level cache I started to see some weird behavior related to embeds in my tests (Foundry started to complain about unsaved changes)
Current behavior
Currently, Foundry complains about unsaved changes, even if there are none being made.
After looking into it it seems that Foundry by @kbond (sorry for the ping, maybe you can look over this as well :) ) is calling
$om->getUnitOfWork()->getEntityChangeSet($this->object)(which is why I'm opening the issue here for now) to determine if there's changes.After looking into what's supposed to have changed, it seems that the
spl_object_idof the embed field in my object changed for some reason (I didn't touch it)How to reproduce
Setup looks like this:
Affected entity:
A project context that determines the project used for the current request:
A listener that sets the project:
The issue is I can't exactly figure out WHY the entity has a changed embed so I can't really tell how to reproduce it (yet, I'm still trying to find it but in the meantime I thought I already mention this because maybe someone can point me in the right direction) but adding
assert($this->project->getInvoiceAddress() instanceof Address);or better generally accessing the embed there "fixes" one of the test errors (but some others still remain) which is a bit strange in itself.Anyone got any idea what's up with this? Or has some pointers for me to dig deeper?
Expected behavior
It correctly detects there are no changes.
@KDederichs commented on GitHub (Dec 1, 2023):
Dug deeper and managed to make a reproducer https://github.com/KDederichs/embed_spl_reproducer , doesn't seem to be related to the context at all since it already happens with just Foundry stuff.
Just composer up -d and run the one test that's in there