UnitOfWork::persisters caches join statements #7484

Open
opened 2026-01-22 15:52:14 +01:00 by admin · 0 comments
Owner

Originally created by @oojacoboo on GitHub (Mar 5, 2025).

Bug Report

Q A
Version 3.3.2

Summary

I've been dealing with an issue where join conditions on a query, combined with a filter, were incorrect. It was using the join conditions from a previous query on the same entity within a loop.

Current behavior

It turns out the issue is related to the UnitOfWork::getEntityPersister method, specifically the use of the persisters property for state/cache.

public function getEntityPersister(string $entityName): EntityPersister
    // This if block is the issue.  When commented out, the issue is resolved.
    if (isset($this->persisters[$entityName])) {
        return $this->persisters[$entityName];
    }
    ...
}

Expected behavior

Avoid caching these persisters, or add improved logic to rebuild the join statement in the EntityPersister instance. I wasn't able to determine the proper way to ensure the selectJoinSql is properly rebuilt when reusing an existing persister instance.

How to reproduce

The issue exists with the BasicEntityPersister::currentPersisterContext->selectJoinSql property. When the persister is cached within the UnitOfWork, this selectJoinSql never gets rebuilt, resulting in an incorrect join statement. It's specifically seen with filter conditions.

Originally created by @oojacoboo on GitHub (Mar 5, 2025). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |-------------------------------------------- | ------ | Version | 3.3.2 #### Summary I've been dealing with an issue where join conditions on a query, combined with a filter, were incorrect. It was using the join conditions from a previous query on the same entity within a loop. #### Current behavior It turns out the issue is related to the `UnitOfWork::getEntityPersister` method, specifically the use of the `persisters` property for state/cache. ```php public function getEntityPersister(string $entityName): EntityPersister // This if block is the issue. When commented out, the issue is resolved. if (isset($this->persisters[$entityName])) { return $this->persisters[$entityName]; } ... } ``` #### Expected behavior Avoid caching these persisters, or add improved logic to rebuild the join statement in the `EntityPersister` instance. I wasn't able to determine the proper way to ensure the `selectJoinSql` is properly rebuilt when reusing an existing persister instance. #### How to reproduce The issue exists with the `BasicEntityPersister::currentPersisterContext->selectJoinSql` property. When the persister is cached within the `UnitOfWork`, this `selectJoinSql` never gets rebuilt, resulting in an incorrect join statement. It's specifically seen with filter conditions.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7484