Partial object children in cache #7183

Closed
opened 2026-01-22 15:46:12 +01:00 by admin · 8 comments
Owner

Originally created by @duzenko on GitHub (Jul 11, 2023).

Bug Report

Q A
BC Break no
Version 2.8

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

		$condition = $e->andX();
		$condition->add( $e->eq( 'la.user', $loaneeId ) );
		$condition->add( $e->in( 'lc.status', [ LoanContract::STATUS_inPreparation, LoanContract::STATUS_legal, LoanContract::STATUS_caseExternal, LoanContract::STATUS_caseInternal ] ) );

		$qb = $this->createQueryBuilder();
		$qb
				->select( 'partial lc.{id}, partial lr.{id}' )
				->from( LoanContract::class, 'lc' )
				->join( 'lc.auction', 'la' )
				->join( 'lc.loaner', 'lr' )
				->where( $condition );

		$q = $qb->getQuery();
		$contracts = $q->getResult();

Later in the same PHP call, but very different class I try to load the auction

		return $this->getRepository()->findOneBy( [ 'extendedWith' => $this->getEntity()->getId() ] );

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

Originally created by @duzenko on GitHub (Jul 11, 2023). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | 2.8 #### 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 ``` $condition = $e->andX(); $condition->add( $e->eq( 'la.user', $loaneeId ) ); $condition->add( $e->in( 'lc.status', [ LoanContract::STATUS_inPreparation, LoanContract::STATUS_legal, LoanContract::STATUS_caseExternal, LoanContract::STATUS_caseInternal ] ) ); $qb = $this->createQueryBuilder(); $qb ->select( 'partial lc.{id}, partial lr.{id}' ) ->from( LoanContract::class, 'lc' ) ->join( 'lc.auction', 'la' ) ->join( 'lc.loaner', 'lr' ) ->where( $condition ); $q = $qb->getQuery(); $contracts = $q->getResult(); ``` Later in the same PHP call, but very different class I try to load the auction ``` return $this->getRepository()->findOneBy( [ 'extendedWith' => $this->getEntity()->getId() ] ); ``` 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
admin closed this issue 2026-01-22 15:46:12 +01:00
Author
Owner

@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?

@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?
Author
Owner

@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

@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
Author
Owner

@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?

@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?
Author
Owner

@derrabus commented on GitHub (Jul 12, 2023):

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?

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): > 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? https://www.doctrine-project.org/projects/doctrine-orm/en/2.15/reference/partial-objects.html The big yellow box at the very top.
Author
Owner

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

@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.
Author
Owner

@duzenko commented on GitHub (Jul 12, 2023):

Here's how I worked around it
image

@duzenko commented on GitHub (Jul 12, 2023): Here's how I worked around it ![image](https://github.com/doctrine/orm/assets/1481807/97784aaf-a373-4d80-8808-2fe67e7950c9)
Author
Owner

@duzenko 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.

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.

@duzenko 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. 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.
Author
Owner

@derrabus commented on GitHub (Jul 12, 2023):

IMHO you could still improve the docs on partial objects

Be my guest, the docs are open source.

@derrabus commented on GitHub (Jul 12, 2023): > IMHO you could still improve the docs on partial objects Be my guest, the docs are open source.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7183