Doctrine\Common\Collections\ArrayCollection::set(): Argument #1 ($key) must be of type string|int, null given, called in /path/to/project/vendor/doctrine/orm/src/PersistentCollection.php on line 162 #7461

Closed
opened 2026-01-22 15:51:56 +01:00 by admin · 10 comments
Owner

Originally created by @savemetenminutes on GitHub (Jan 15, 2025).

Bug Report

Q A
Version 3.3.1
Previous Version if the bug is a regression 3.3.0

Summary

A regression was introduced by this commit:
439b4dacf4/#diff-ecc4306d602db732bf06eda6ac0fc41b23fe8a25f4a2548196f813f30dd2ac35R1277

  1. Have an entity with a one-to-many relation
  2. Define index-by in the mapping
  3. Within the same UnitOfWork perform (Edit: this probably happens every time an entity is fetched for a second time as part of a collection which has index-by defined in the mapping after enabling or disabling a filter, which causes the persister's filter hash to change):
  • $childEntity->getParent() so that it goes through vendor/doctrine/orm/src/Proxy/ProxyFactory.php:279
    $entityPersister = $this->uow->getEntityPersister($className);
  • enable a doctrine filter, which changes the $this->filterHash of the BasicEntityPersister
  • $parentEntity->getChildCollection() so that it goes through vendor/doctrine/orm/src/UnitOfWork.php:2702
    $persister = $this->getEntityPersister($assoc->targetEntity);
  1. This will cause the same instance of the BasicEntityPersister to populate its ->currentPersisterContext->rsm instance of ResultSetMapping by calling the ->addFieldResult twice for each ChildEntity column. So the ResultSetMapping->fieldMappings array in the end will hold each entity column twice, but with different alias (index). The \Doctrine\ORM\Persisters\Entity\BasicEntityPersister::getSelectColumnsSQL() mechanism for detecting whether the current instance has already calculated the select columns from a previous query
    vendor/doctrine/orm/src/Persisters/Entity/BasicEntityPersister.php:1234
    if ($this->currentPersisterContext->selectColumnListSql !== null && $this->filterHash === $this->em->getFilters()->getHash()) {
    is bypassed due to the new filter hash, but the ->currentPersisterContext->sqlAliasCounter is not reset and
    vendor/doctrine/orm/src/Persisters/Entity/BasicEntityPersister.php:1243
    $columnList[] = $this->getSelectColumnSQL($field, $this->class);
    will result in
    \Doctrine\ORM\Persisters\Entity\BasicEntityPersister::getSQLColumnAlias()
    to keep incrementing the
    $this->currentPersisterContext->sqlAliasCounter++
    from the position it was left at from the previous query, thus the second column set with the greater alias indexes will eventually be fetched in the result row. Due to the entity persister's ResultSetMapping instance's ->indexByMap pointing to the alias with the lesser index the following happens:
    vendor/doctrine/orm/src/Internal/Hydration/ObjectHydrator.php:498
    $resultKey = $row[$this->resultSetMapping()->indexByMap[$dqlAlias]];
    Here $resultKey becomes null and
    $this->hints['collection']->hydrateSet($resultKey, $element);
    in turn calls
    vendor/doctrine/orm/src/PersistentCollection.php:162
    $this->unwrap()->set($key, $element);
    resulting in the exception from the title of the issue.

Current behavior

An exception is thrown.

Expected behavior

Collection indexing used to work in this case in version 3.3.0 of doctrine/orm

How to reproduce

Providing partial stack traces of the two fetches within the same UnitOfWork - with the breakpoint set at the problematic double addition of the columns in the ResultSetMapping->fieldMappings.

ResultSetMapping.php:327, Doctrine\ORM\Query\ResultSetMapping->addFieldResult()
BasicEntityPersister.php:1505, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectColumnSQL()
BasicEntityPersister.php:1243, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectColumnsSQL()
BasicEntityPersister.php:1119, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectSQL()
BasicEntityPersister.php:734, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->load()
BasicEntityPersister.php:754, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadById()
ProxyFactory.php:220, Doctrine\ORM\Proxy\ProxyFactory::Doctrine\ORM\Proxy\{closure:/path/to/project/vendor/doctrine/orm/src/Proxy/ProxyFactory.php:219-242}()
ProxyFactory.php:286, Doctrine\Entities\__CG__\Devision\Auth\Context\UserClient\Domain\UserClient::Doctrine\ORM\Proxy\{closure:/path/to/project/vendor/doctrine/orm/src/Proxy/ProxyFactory.php:285-287}()
LazyObjectState.php:100, Symfony\Component\VarExporter\Internal\LazyObjectState->initialize()
LazyGhostTrait.php:178, Doctrine\Entities\__CG__\Devision\Auth\Context\UserClient\Domain\UserClient->__get()
UserClient.php:51, Devision\Auth\Context\UserClient\Domain\UserClient->getUser()
ResultSetMapping.php:327, Doctrine\ORM\Query\ResultSetMapping->addFieldResult()
BasicEntityPersister.php:1505, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectColumnSQL()
BasicEntityPersister.php:1243, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectColumnsSQL()
BasicEntityPersister.php:1119, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectSQL()
BasicEntityPersister.php:1831, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getOneToManyStatement()
BasicEntityPersister.php:1779, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadOneToManyCollection()
UnitOfWork.php:2706, Doctrine\ORM\UnitOfWork->loadCollection()
PersistentCollection.php:636, Doctrine\ORM\PersistentCollection->doInitialize()
PersistentCollection.php:186, Doctrine\ORM\PersistentCollection->initialize()
AbstractLazyCollection.php:138, Doctrine\Common\Collections\AbstractLazyCollection->getValues()
User.php:287, Devision\Auth\Context\User\Domain\User->getUserClientCollection()

And a JSON formatted partial stack trace of the Exception:

            "message": "Doctrine\\Common\\Collections\\ArrayCollection::set(): Argument #1 ($key) must be of type string|int, null given, called in /path/to/project/vendor/doctrine/orm/src/PersistentCollection.php on line 162",
            "code": 0,
            "type": "TypeError",
            "file:line": "/path/to/project/vendor/doctrine/collections/src/ArrayCollection.php:310",
            "previous": null,
            "trace": [
                {
                    "file:line": "/path/to/project/vendor/doctrine/orm/src/PersistentCollection.php:162",
                    "callee": "Doctrine\\Common\\Collections\\ArrayCollection->set",
                    "args": [
                        "NULL",
                        "{instanceof Devision\\Auth\\Context\\UserClient\\Domain\\UserClient}"
                    ]
                },
                {
                    "file:line": "/path/to/project/vendor/doctrine/orm/src/Internal/Hydration/ObjectHydrator.php:501",
                    "callee": "Doctrine\\ORM\\PersistentCollection->hydrateSet",
                    "args": [
                        "NULL",
                        "{instanceof Devision\\Auth\\Context\\UserClient\\Domain\\UserClient}"
                    ]
                },
                {
                    "file:line": "/path/to/project/vendor/doctrine/orm/src/Internal/Hydration/ObjectHydrator.php:143",
                    "callee": "Doctrine\\ORM\\Internal\\Hydration\\ObjectHydrator->hydrateRowData",
                    "args": [
                        "array (  'uuid_9' => '\\'<REDACTED>\\'',  'created_10' => '\\'<REDACTED>\\'',  'modified_11' => '\\'<REDACTED>\\'',  'not_archived_12' => '<REDACTED>',  'archived_13' => 'NULL',  'id_14' => '<REDACTED>',  'auth_user_id_15' => '<REDACTED>',  'auth_client_id_16' => '<REDACTED>',)",
                        "array ()"
                    ]
                },
                {
                    "file:line": "/path/to/project/vendor/doctrine/orm/src/Internal/Hydration/AbstractHydrator.php:168",
                    "callee": "Doctrine\\ORM\\Internal\\Hydration\\ObjectHydrator->hydrateAllData",
                    "args": []
                },
                {
                    "file:line": "/path/to/project/vendor/doctrine/orm/src/Persisters/Entity/BasicEntityPersister.php:1001",
                    "callee": "Doctrine\\ORM\\Internal\\Hydration\\AbstractHydrator->hydrateAll",
                    "args": [
                        "{instanceof Doctrine\\DBAL\\Result}",
                        "{instanceof Doctrine\\ORM\\Query\\ResultSetMapping}",
                        "array (  'deferEagerLoad' => 'true',  'collection' => '{instanceof Doctrine\\\\ORM\\\\PersistentCollection}',)"
                    ]
                },
                {
                    "file:line": "/path/to/project/vendor/doctrine/orm/src/Persisters/Entity/BasicEntityPersister.php:1781",
                    "callee": "Doctrine\\ORM\\Persisters\\Entity\\BasicEntityPersister->loadCollectionFromStatement",
                    "args": [
                        "{instanceof Doctrine\\ORM\\Mapping\\OneToManyAssociationMapping}",
                        "{instanceof Doctrine\\DBAL\\Result}",
                        "{instanceof Doctrine\\ORM\\PersistentCollection}"
                    ]
                },
                {
                    "file:line": "/path/to/project/vendor/doctrine/orm/src/UnitOfWork.php:2706",
                    "callee": "Doctrine\\ORM\\Persisters\\Entity\\BasicEntityPersister->loadOneToManyCollection",
                    "args": [
                        "{instanceof Doctrine\\ORM\\Mapping\\OneToManyAssociationMapping}",
                        "{instanceof Devision\\Auth\\Context\\User\\Domain\\User}",
                        "{instanceof Doctrine\\ORM\\PersistentCollection}"
                    ]
                },
                {
                    "file:line": "/path/to/project/vendor/doctrine/orm/src/PersistentCollection.php:636",
                    "callee": "Doctrine\\ORM\\UnitOfWork->loadCollection",
                    "args": [
                        "{instanceof Doctrine\\ORM\\PersistentCollection}"
                    ]
                },
                {
                    "file:line": "/path/to/project/vendor/doctrine/orm/src/PersistentCollection.php:186",
                    "callee": "Doctrine\\ORM\\PersistentCollection->doInitialize",
                    "args": []
                },
                {
                    "file:line": "/path/to/project/vendor/doctrine/collections/src/AbstractLazyCollection.php:138",
                    "callee": "Doctrine\\ORM\\PersistentCollection->initialize",
                    "args": []
                },
                {
                    "file:line": "/path/to/project/vendor/devision/devision-auth/src/Context/User/Domain/User.php:287",
                    "callee": "Doctrine\\Common\\Collections\\AbstractLazyCollection->getValues",
                    "args": []
                },
                {
                    "file:line": "/path/to/project/vendor/devision/adex-sales/src/Context/Auth/Context/User/Application/Service/UserService.php:292",
                    "callee": "Devision\\Auth\\Context\\User\\Domain\\User->getUserClientCollection",
                    "args": []
                },
Originally created by @savemetenminutes on GitHub (Jan 15, 2025). ### Bug Report | Q | A |-------------------------------------------- | ------ | Version | 3.3.1 | Previous Version if the bug is a regression | 3.3.0 #### Summary A regression was introduced by this commit: https://github.com/doctrine/orm/commit/439b4dacf415b743b0d40d65c490a4123759c520/#diff-ecc4306d602db732bf06eda6ac0fc41b23fe8a25f4a2548196f813f30dd2ac35R1277 1. Have an entity with a one-to-many relation 2. Define index-by in the mapping 3. Within the same UnitOfWork perform (Edit: this probably happens every time an entity is fetched for a second time as part of a collection which has index-by defined in the mapping after enabling or disabling a filter, which causes the persister's filter hash to change): - `$childEntity->getParent()` so that it goes through `vendor/doctrine/orm/src/Proxy/ProxyFactory.php:279` `$entityPersister = $this->uow->getEntityPersister($className);` - enable a doctrine filter, which changes the `$this->filterHash` of the BasicEntityPersister - `$parentEntity->getChildCollection()` so that it goes through `vendor/doctrine/orm/src/UnitOfWork.php:2702` `$persister = $this->getEntityPersister($assoc->targetEntity);` 4. This will cause the same instance of the BasicEntityPersister to populate its `->currentPersisterContext->rsm` instance of ResultSetMapping by calling the `->addFieldResult` twice for each ChildEntity column. So the `ResultSetMapping->fieldMappings` array in the end will hold each entity column twice, but with different alias (index). The `\Doctrine\ORM\Persisters\Entity\BasicEntityPersister::getSelectColumnsSQL()` mechanism for detecting whether the current instance has already calculated the select columns from a previous query `vendor/doctrine/orm/src/Persisters/Entity/BasicEntityPersister.php:1234` `if ($this->currentPersisterContext->selectColumnListSql !== null && $this->filterHash === $this->em->getFilters()->getHash()) {` is bypassed due to the new filter hash, but the `->currentPersisterContext->sqlAliasCounter` is not reset and `vendor/doctrine/orm/src/Persisters/Entity/BasicEntityPersister.php:1243` `$columnList[] = $this->getSelectColumnSQL($field, $this->class);` will result in `\Doctrine\ORM\Persisters\Entity\BasicEntityPersister::getSQLColumnAlias()` to keep incrementing the `$this->currentPersisterContext->sqlAliasCounter++` from the position it was left at from the previous query, thus the second column set with the greater alias indexes will eventually be fetched in the result row. Due to the entity persister's ResultSetMapping instance's `->indexByMap` pointing to the alias with the lesser index the following happens: `vendor/doctrine/orm/src/Internal/Hydration/ObjectHydrator.php:498` `$resultKey = $row[$this->resultSetMapping()->indexByMap[$dqlAlias]];` Here `$resultKey` becomes null and `$this->hints['collection']->hydrateSet($resultKey, $element);` in turn calls `vendor/doctrine/orm/src/PersistentCollection.php:162` `$this->unwrap()->set($key, $element);` resulting in the exception from the title of the issue. #### Current behavior An exception is thrown. #### Expected behavior Collection indexing used to work in this case in version 3.3.0 of `doctrine/orm` #### How to reproduce Providing partial stack traces of the two fetches within the same UnitOfWork - with the breakpoint set at the problematic double addition of the columns in the `ResultSetMapping->fieldMappings`. 1. ``` ResultSetMapping.php:327, Doctrine\ORM\Query\ResultSetMapping->addFieldResult() BasicEntityPersister.php:1505, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectColumnSQL() BasicEntityPersister.php:1243, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectColumnsSQL() BasicEntityPersister.php:1119, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectSQL() BasicEntityPersister.php:734, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->load() BasicEntityPersister.php:754, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadById() ProxyFactory.php:220, Doctrine\ORM\Proxy\ProxyFactory::Doctrine\ORM\Proxy\{closure:/path/to/project/vendor/doctrine/orm/src/Proxy/ProxyFactory.php:219-242}() ProxyFactory.php:286, Doctrine\Entities\__CG__\Devision\Auth\Context\UserClient\Domain\UserClient::Doctrine\ORM\Proxy\{closure:/path/to/project/vendor/doctrine/orm/src/Proxy/ProxyFactory.php:285-287}() LazyObjectState.php:100, Symfony\Component\VarExporter\Internal\LazyObjectState->initialize() LazyGhostTrait.php:178, Doctrine\Entities\__CG__\Devision\Auth\Context\UserClient\Domain\UserClient->__get() UserClient.php:51, Devision\Auth\Context\UserClient\Domain\UserClient->getUser() ``` 2. ``` ResultSetMapping.php:327, Doctrine\ORM\Query\ResultSetMapping->addFieldResult() BasicEntityPersister.php:1505, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectColumnSQL() BasicEntityPersister.php:1243, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectColumnsSQL() BasicEntityPersister.php:1119, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectSQL() BasicEntityPersister.php:1831, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getOneToManyStatement() BasicEntityPersister.php:1779, Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadOneToManyCollection() UnitOfWork.php:2706, Doctrine\ORM\UnitOfWork->loadCollection() PersistentCollection.php:636, Doctrine\ORM\PersistentCollection->doInitialize() PersistentCollection.php:186, Doctrine\ORM\PersistentCollection->initialize() AbstractLazyCollection.php:138, Doctrine\Common\Collections\AbstractLazyCollection->getValues() User.php:287, Devision\Auth\Context\User\Domain\User->getUserClientCollection() ``` And a JSON formatted partial stack trace of the Exception: ``` "message": "Doctrine\\Common\\Collections\\ArrayCollection::set(): Argument #1 ($key) must be of type string|int, null given, called in /path/to/project/vendor/doctrine/orm/src/PersistentCollection.php on line 162", "code": 0, "type": "TypeError", "file:line": "/path/to/project/vendor/doctrine/collections/src/ArrayCollection.php:310", "previous": null, "trace": [ { "file:line": "/path/to/project/vendor/doctrine/orm/src/PersistentCollection.php:162", "callee": "Doctrine\\Common\\Collections\\ArrayCollection->set", "args": [ "NULL", "{instanceof Devision\\Auth\\Context\\UserClient\\Domain\\UserClient}" ] }, { "file:line": "/path/to/project/vendor/doctrine/orm/src/Internal/Hydration/ObjectHydrator.php:501", "callee": "Doctrine\\ORM\\PersistentCollection->hydrateSet", "args": [ "NULL", "{instanceof Devision\\Auth\\Context\\UserClient\\Domain\\UserClient}" ] }, { "file:line": "/path/to/project/vendor/doctrine/orm/src/Internal/Hydration/ObjectHydrator.php:143", "callee": "Doctrine\\ORM\\Internal\\Hydration\\ObjectHydrator->hydrateRowData", "args": [ "array ( 'uuid_9' => '\\'<REDACTED>\\'', 'created_10' => '\\'<REDACTED>\\'', 'modified_11' => '\\'<REDACTED>\\'', 'not_archived_12' => '<REDACTED>', 'archived_13' => 'NULL', 'id_14' => '<REDACTED>', 'auth_user_id_15' => '<REDACTED>', 'auth_client_id_16' => '<REDACTED>',)", "array ()" ] }, { "file:line": "/path/to/project/vendor/doctrine/orm/src/Internal/Hydration/AbstractHydrator.php:168", "callee": "Doctrine\\ORM\\Internal\\Hydration\\ObjectHydrator->hydrateAllData", "args": [] }, { "file:line": "/path/to/project/vendor/doctrine/orm/src/Persisters/Entity/BasicEntityPersister.php:1001", "callee": "Doctrine\\ORM\\Internal\\Hydration\\AbstractHydrator->hydrateAll", "args": [ "{instanceof Doctrine\\DBAL\\Result}", "{instanceof Doctrine\\ORM\\Query\\ResultSetMapping}", "array ( 'deferEagerLoad' => 'true', 'collection' => '{instanceof Doctrine\\\\ORM\\\\PersistentCollection}',)" ] }, { "file:line": "/path/to/project/vendor/doctrine/orm/src/Persisters/Entity/BasicEntityPersister.php:1781", "callee": "Doctrine\\ORM\\Persisters\\Entity\\BasicEntityPersister->loadCollectionFromStatement", "args": [ "{instanceof Doctrine\\ORM\\Mapping\\OneToManyAssociationMapping}", "{instanceof Doctrine\\DBAL\\Result}", "{instanceof Doctrine\\ORM\\PersistentCollection}" ] }, { "file:line": "/path/to/project/vendor/doctrine/orm/src/UnitOfWork.php:2706", "callee": "Doctrine\\ORM\\Persisters\\Entity\\BasicEntityPersister->loadOneToManyCollection", "args": [ "{instanceof Doctrine\\ORM\\Mapping\\OneToManyAssociationMapping}", "{instanceof Devision\\Auth\\Context\\User\\Domain\\User}", "{instanceof Doctrine\\ORM\\PersistentCollection}" ] }, { "file:line": "/path/to/project/vendor/doctrine/orm/src/PersistentCollection.php:636", "callee": "Doctrine\\ORM\\UnitOfWork->loadCollection", "args": [ "{instanceof Doctrine\\ORM\\PersistentCollection}" ] }, { "file:line": "/path/to/project/vendor/doctrine/orm/src/PersistentCollection.php:186", "callee": "Doctrine\\ORM\\PersistentCollection->doInitialize", "args": [] }, { "file:line": "/path/to/project/vendor/doctrine/collections/src/AbstractLazyCollection.php:138", "callee": "Doctrine\\ORM\\PersistentCollection->initialize", "args": [] }, { "file:line": "/path/to/project/vendor/devision/devision-auth/src/Context/User/Domain/User.php:287", "callee": "Doctrine\\Common\\Collections\\AbstractLazyCollection->getValues", "args": [] }, { "file:line": "/path/to/project/vendor/devision/adex-sales/src/Context/Auth/Context/User/Application/Service/UserService.php:292", "callee": "Devision\\Auth\\Context\\User\\Domain\\User->getUserClientCollection", "args": [] }, ```
admin closed this issue 2026-01-22 15:51:56 +01:00
Author
Owner

@greg0ire commented on GitHub (Jan 16, 2025):

cc @dbannik

@greg0ire commented on GitHub (Jan 16, 2025): cc @dbannik
Author
Owner

@savemetenminutes commented on GitHub (Apr 3, 2025):

Is @dbannik an active contributor or just did a one time patch for his use case? It's been 3 months now.

@savemetenminutes commented on GitHub (Apr 3, 2025): Is @dbannik an active contributor or just did a one time patch for his use case? It's been 3 months now.
Author
Owner

@dbannik commented on GitHub (Apr 7, 2025):

@savemetenminutes Could you please provide some code to reproduce this error?

@dbannik commented on GitHub (Apr 7, 2025): @savemetenminutes Could you please provide some code to reproduce this error?
Author
Owner

@savemetenminutes commented on GitHub (Apr 9, 2025):

@savemetenminutes Could you please provide some code to reproduce this error?

@dbannik

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity
            name="Something"
            table="something"
            repository-class="SomethingRepository"
            change-tracking-policy="DEFERRED_EXPLICIT"
    >
        <id name="id" type="integer" column="id">
            <generator strategy="IDENTITY"/>
        </id>
        <one-to-many
                field="somethingElseCollection"
                target-entity="SomethingElse"
                mapped-by="user"
                index-by="id"
                fetch="LAZY"
        />
    </entity>
</doctrine-mapping>
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity
            name="SomethingElse"
            table="something_else"
            repository-class="SomethingElseRepository"
            change-tracking-policy="DEFERRED_EXPLICIT"
    >
        <id name="id" type="integer" column="id">
            <generator strategy="IDENTITY"/>
        </id>
        <many-to-one field="something" target-entity="Something">
            <join-column name="something_id" referenced-column-name="id" />
        </many-to-one>
    </entity>
</doctrine-mapping>
<?php

declare(strict_types=1);

use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query\Filter\SQLFilter;

class SomeKindOfFilter extends SQLFilter
{
    public const NAME = 'someKindOfFilter';

    public function addFilterConstraint(ClassMetadata $targetEntity, string $targetTableAlias): string
    {
        /**
         * This should be enough to change the filter hash
         */
        return <<< EOT
        TRUE
        EOT;
    }
}
$somethingElseCollection = $em->getRepository(SomethingElse::class)->findBy([]);
$something = $somethingElseCollection[0]->getSomething();
$em->getFilters()->enable(SomeKindOfFilter::NAME);
$something->getSomethingElseCollection();
@savemetenminutes commented on GitHub (Apr 9, 2025): > [@savemetenminutes](https://github.com/savemetenminutes) Could you please provide some code to reproduce this error? @dbannik ``` <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="Something" table="something" repository-class="SomethingRepository" change-tracking-policy="DEFERRED_EXPLICIT" > <id name="id" type="integer" column="id"> <generator strategy="IDENTITY"/> </id> <one-to-many field="somethingElseCollection" target-entity="SomethingElse" mapped-by="user" index-by="id" fetch="LAZY" /> </entity> </doctrine-mapping> ``` ``` <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="SomethingElse" table="something_else" repository-class="SomethingElseRepository" change-tracking-policy="DEFERRED_EXPLICIT" > <id name="id" type="integer" column="id"> <generator strategy="IDENTITY"/> </id> <many-to-one field="something" target-entity="Something"> <join-column name="something_id" referenced-column-name="id" /> </many-to-one> </entity> </doctrine-mapping> ``` ``` <?php declare(strict_types=1); use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\Filter\SQLFilter; class SomeKindOfFilter extends SQLFilter { public const NAME = 'someKindOfFilter'; public function addFilterConstraint(ClassMetadata $targetEntity, string $targetTableAlias): string { /** * This should be enough to change the filter hash */ return <<< EOT TRUE EOT; } } ``` ``` $somethingElseCollection = $em->getRepository(SomethingElse::class)->findBy([]); $something = $somethingElseCollection[0]->getSomething(); $em->getFilters()->enable(SomeKindOfFilter::NAME); $something->getSomethingElseCollection(); ```
Author
Owner

@dbannik commented on GitHub (Apr 10, 2025):

@savemetenminutes I couldn't reproduce the error
DIFF: 4340fe243eff0259f17b8c964bf70c5febd34233

Executed sql in test

CREATE TABLE Something (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)
CREATE TABLE SomethingElse (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, something_id INTEGER DEFAULT NULL, CONSTRAINT FK_30323A707F8B6570 FOREIGN KEY (something_id) REFERENCES Something (id) NOT DEFERRABLE INITIALLY IMMEDIATE)
CREATE INDEX IDX_30323A707F8B6570 ON SomethingElse (something_id)
INSERT INTO Something (id) VALUES (null)
INSERT INTO SomethingElse (something_id) VALUES (?)
SELECT t0.id AS id_1, t0.something_id AS something_id_2 FROM SomethingElse t0
SELECT t0.id AS id_1 FROM Something t0 WHERE t0.id = ? AND ((TRUE))
SELECT t0.id AS id_1, t0.something_id AS something_id_3 FROM SomethingElse t0 WHERE t0.something_id = ? AND ((TRUE))
@dbannik commented on GitHub (Apr 10, 2025): @savemetenminutes I couldn't reproduce the error DIFF: [4340fe243eff0259f17b8c964bf70c5febd34233](https://github.com/doctrine/orm/compare/3.3.x...dbannik:orm:3.3.x-reproduce-issue-11790) **Executed sql in test** ```sql CREATE TABLE Something (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL) CREATE TABLE SomethingElse (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, something_id INTEGER DEFAULT NULL, CONSTRAINT FK_30323A707F8B6570 FOREIGN KEY (something_id) REFERENCES Something (id) NOT DEFERRABLE INITIALLY IMMEDIATE) CREATE INDEX IDX_30323A707F8B6570 ON SomethingElse (something_id) INSERT INTO Something (id) VALUES (null) INSERT INTO SomethingElse (something_id) VALUES (?) SELECT t0.id AS id_1, t0.something_id AS something_id_2 FROM SomethingElse t0 SELECT t0.id AS id_1 FROM Something t0 WHERE t0.id = ? AND ((TRUE)) SELECT t0.id AS id_1, t0.something_id AS something_id_3 FROM SomethingElse t0 WHERE t0.something_id = ? AND ((TRUE)) ```
Author
Owner

@savemetenminutes commented on GitHub (Apr 10, 2025):

@dbannik I don't see the index-by="id" on the one-to-many relation. All relations should be lazy fetched.

@savemetenminutes commented on GitHub (Apr 10, 2025): @dbannik I don't see the `index-by="id"` on the one-to-many relation. All relations should be lazy fetched.
Author
Owner

@dbannik commented on GitHub (Apr 11, 2025):

18b8ea7fc1
@savemetenminutes did not change the situation. Provide a test that will not pass on your problem!

@dbannik commented on GitHub (Apr 11, 2025): https://github.com/dbannik/orm/commit/18b8ea7fc1e9082e89b5256d8d24a4d404062fd6 @savemetenminutes did not change the situation. Provide a test that will not pass on your problem!
Author
Owner

@savemetenminutes commented on GitHub (Apr 13, 2025):

@dbannik someone has fixed your regression in 3.3.2 in this commit:
6755bb0c7b

In the future please pay attention to the description of the issues! I have provided more than enough information on the the issue, how to reproduce it and the circumstances around it, including the version, which introduces this issue:

Version | 3.3.1
Previous Version if the bug is a regression | 3.3.0

@savemetenminutes commented on GitHub (Apr 13, 2025): @dbannik someone has fixed your regression in 3.3.2 in this commit: https://github.com/doctrine/orm/commit/6755bb0c7bdb1774152fddf7bb0ff20a4dd5a8a0 In the future please pay attention to the description of the issues! I have provided more than enough information on the the issue, how to reproduce it and the circumstances around it, including the version, which introduces this issue: > Version | 3.3.1 > Previous Version if the bug is a regression | 3.3.0
Author
Owner

@dbannik commented on GitHub (Apr 13, 2025):

I'm glad that everything has been fixed for you
From now on, check the latest versions of the package for errors, as they may have already been fixed by other project contributions!

@dbannik commented on GitHub (Apr 13, 2025): I'm glad that everything has been fixed for you From now on, check the latest versions of the package for errors, as they may have already been fixed by other project contributions!
Author
Owner

@savemetenminutes commented on GitHub (Apr 14, 2025):

I'm sure that eventually, after enough time has passed, they will...

@savemetenminutes commented on GitHub (Apr 14, 2025): I'm sure that eventually, after enough time has passed, they will...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7461