mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Partial object children in cache #7183
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 @duzenko on GitHub (Jul 11, 2023).
Bug Report
Summary
Partial objects break object caching
Current behavior
Incomplete joined objects from partial selects save to cache and later are reused without actual data fetch
How to reproduce
Partial select with join. In this case 'lc.auction la' is the no-data object that is saved to cache
Later in the same PHP call, but very different class I try to load the auction
The auction itself loads OK, but its nested contracts collection only has id's, all other fields are null.
Auction and contracts link to each other via a one-to-many and many-to-one relations.
There may be a bug in the code that checks the 'initialized' state of the partial contract entity that prevents it to load the second time.
So either prevent the auction entity from saving to cache, or make the partial contract entity to reload on next fetch.
Expected behavior
The partial objects do not save to cache and are fully loaded on subsequent requests
@duzenko commented on GitHub (Jul 11, 2023):
I can see a related issue for version 2.7 but I have 2.8 and my case is still broken - I'm not sure if it's because the second-level join objects being the problem here or I need to pass additional explicit parameters during the call to get partial objects so that they are not saved to cache?
@beberlei commented on GitHub (Jul 11, 2023):
Partial objects are deprecated and will be removed in 3.0 because of issues like this.
We wont fix this anymore, use dql new dto instead of partial objects to avoid this in 2.x
@duzenko commented on GitHub (Jul 12, 2023):
@beberlei So this is a known issue? Where in the docs can I see that partial objects should not be used because they mess up the cache?
And could you please elaborate on the suggested alternative please?
@derrabus commented on GitHub (Jul 12, 2023):
https://www.doctrine-project.org/projects/doctrine-orm/en/2.15/reference/partial-objects.html
The big yellow box at the very top.
@derrabus commented on GitHub (Jul 12, 2023):
Also, please stop opening issues for unmaintained versions. In this case you're reporting issues for ORM 2.8 which is obsolete for over two years. Even if you've discovered a bug that needs a fix, we won't backport it for you.
@duzenko commented on GitHub (Jul 12, 2023):
Here's how I worked around it

@duzenko commented on GitHub (Jul 12, 2023):
IMHO you could still improve the docs on partial objects in any/current version to state that partial objects will keep been returned from ORM on unrelated data reads - there's no way an average person would deduct that from your yellow boxes.
@derrabus commented on GitHub (Jul 12, 2023):
Be my guest, the docs are open source.