Bug when use Featch EGER and SQLFilter #7126

Closed
opened 2026-01-22 15:45:16 +01:00 by admin · 5 comments
Owner

Originally created by @dbannik on GitHub (Apr 2, 2023).

Bug Report

Q A
BC Break yes
Version 2.14.x

Summary

There is entity:
Patient
with property collection Order (orders with Fetch EGER)

Order
with property Practice (sets SQLFilter of current Company in system)

Company is system: 1, 2

When first entity load Patient with Company 1 is good
When (SQLFilter update parameter to Company 2) and load next Patient , Orders collection load with practice 1 in SQL QUERY!

Current behavior

Cached Join sql in persist entity (Patient) if use Fetch EGER property
If change SQLFilter parameter, cached join sql does not refreshed and used old sql join parameters!

entityManager->clear() persisted entity metadata does not removed!

How to reproduce

Entity: Company
Entity: Patient
Entity: Order

Patient -> OneToMany (Fetch EGER) -> Order
Order -> ManyToOne -> Company

SQLFilter set parameter Company 1 (added to Order filter)

Expected behavior

When switch SQLFilter parameter (Company) join sql should be refreshed with actual SQLFilters!

Originally created by @dbannik on GitHub (Apr 2, 2023). ### Bug Report | Q | A |------------ | ------ | BC Break | yes | Version | 2.14.x #### Summary There is entity: `Patient` with property collection `Order` (orders with Fetch EGER) `Order` with property `Practice` (sets SQLFilter of current Company in system) Company is system: `1`, `2` When first entity load `Patient` with Company `1` is good When (SQLFilter update parameter to Company `2`) and load next `Patient` , Orders collection load with practice `1` in SQL QUERY! #### Current behavior Cached `Join sql` in persist entity (Patient) if use `Fetch EGER` property If change SQLFilter parameter, cached join sql does not refreshed and used old sql join parameters! _entityManager->clear() persisted entity metadata does not removed!_ #### How to reproduce Entity: Company Entity: Patient Entity: Order Patient -> OneToMany (Fetch EGER) -> Order Order -> ManyToOne -> Company SQLFilter set parameter Company `1` (added to `Order` filter) #### Expected behavior When switch SQLFilter parameter (Company) join sql should be refreshed with actual SQLFilters!
admin added the BugWaiting feedback labels 2026-01-22 15:45:16 +01:00
admin closed this issue 2026-01-22 15:45:16 +01:00
Author
Owner

@derrabus commented on GitHub (Apr 3, 2023):

I'm sorry, I don't really understand this bug report. I tried to make sense of the test you've provided in your PR but that confuses me even more. Can you please elaborate again in full sentences…

  • what you're trying to do
  • how you're trying to achive that
  • why you believe that the ORMs current behavior is wrong?
@derrabus commented on GitHub (Apr 3, 2023): I'm sorry, I don't really understand this bug report. I tried to make sense of the test you've provided in your PR but that confuses me even more. Can you please elaborate again in full sentences… * what you're trying to do * how you're trying to achive that * why you believe that the ORMs current behavior is wrong?
Author
Owner

@dbannik commented on GitHub (Apr 3, 2023):

@derrabus
I have an orm running in a message queue and I need to be able to switch context using SQL filters.
when changing the context of the "filter options" I want to get the correct correct answer result!
but when changing the filter parameter now the join is cached from the previous filter

@dbannik commented on GitHub (Apr 3, 2023): @derrabus I have an orm running in a message queue and I need to be able to switch context using SQL filters. when changing the context of the "filter options" I want to get the correct correct answer result! but when changing the filter parameter now the join is cached from the previous filter
Author
Owner

@jelovac commented on GitHub (Jun 5, 2023):

@derrabus ,

I think I am experiencing the same issue as the author.

Take a look at the following piece of code:

// vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php

    protected function hydrateAllData()
    {
        $result = [];

        while ($row = $this->statement()->fetchAssociative()) {
            $this->hydrateRowData($row, $result);
        }

What happens is that for some reason $this->statement()->fetchAssociative() returns wrong result set.

In my case it seems that this happens when there were already queries against database for the same entity.

When I inspect using xdebug the $this->statement object I can see that it is an instance of \Doctrine\DBAL\Driver\PDO\Result and navigating inside it I can see that actual \PDOStatement object contains the SQL Filter part. However when statement is iterated over using fetchAssociative() it includes rows which shouldn't be there.

I am suspecting that there is some kind of cache involved.

@jelovac commented on GitHub (Jun 5, 2023): @derrabus , I think I am experiencing the same issue as the author. Take a look at the following piece of code: ``` // vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php protected function hydrateAllData() { $result = []; while ($row = $this->statement()->fetchAssociative()) { $this->hydrateRowData($row, $result); } ``` What happens is that for some reason `$this->statement()->fetchAssociative()` returns wrong result set. In my case it seems that this happens when there were already queries against database for the same entity. When I inspect using xdebug the $this->statement object I can see that it is an instance of `\Doctrine\DBAL\Driver\PDO\Result` and navigating inside it I can see that actual `\PDOStatement` object contains the SQL Filter part. However when statement is iterated over using `fetchAssociative()` it includes rows which shouldn't be there. I am suspecting that there is some kind of cache involved.
Author
Owner

@derrabus commented on GitHub (Jun 5, 2023):

Same questions for you then: https://github.com/doctrine/orm/issues/10610#issuecomment-1494241046

I need clear steps to reproduce the issue before I can help you.

@derrabus commented on GitHub (Jun 5, 2023): Same questions for you then: https://github.com/doctrine/orm/issues/10610#issuecomment-1494241046 I need clear steps to reproduce the issue before I can help you.
Author
Owner

@jelovac commented on GitHub (Jun 6, 2023):

Same questions for you then: #10610 (comment)

I need clear steps to reproduce the issue before I can help you.

I was wrong. My subquery condition in the filter was bad. And as I troubleshooted directly on the test database the generated PDO statement SQL I though that the filter was working because it was missing one row which I intended to filter. However, I forgot that I am using test environment and that records which are inserted during tests are not commited to the test DB (Doctrine Test Bundle). So the row was missing from the result set because it was never actually inserted.

So not an issue for me anymore.

@jelovac commented on GitHub (Jun 6, 2023): > Same questions for you then: [#10610 (comment)](https://github.com/doctrine/orm/issues/10610#issuecomment-1494241046) > > I need clear steps to reproduce the issue before I can help you. I was wrong. My subquery condition in the filter was bad. And as I troubleshooted directly on the test database the generated PDO statement SQL I though that the filter was working because it was missing one row which I intended to filter. However, I forgot that I am using test environment and that records which are inserted during tests are not commited to the test DB (Doctrine Test Bundle). So the row was missing from the result set because it was never actually inserted. So not an issue for me anymore.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7126