You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
#11790
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);
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.
The text was updated successfully, but these errors were encountered:
savemetenminutes
changed the title
Doctrine\Common\Collections\ArrayCollection::set(): Argument #1 ($key) must be of type string|int, null given, called in /var/www/content/adex-sales/vendor/doctrine/orm/src/PersistentCollection.php on line 162
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
Jan 15, 2025
…ters
CachedPersisterContext::$selectJoinSql should be clear or regenerated when sqlFilter changed
The problem reproduce when in use fetch=EAGER and use additional sql filter on this property
Bug Report
Summary
A regression was introduced by this commit:
https://github.com/doctrine/orm/commit/439b4dacf415b743b0d40d65c490a4123759c520/#diff-ecc4306d602db732bf06eda6ac0fc41b23fe8a25f4a2548196f813f30dd2ac35R1277
$childEntity->getParent()
so that it goes throughvendor/doctrine/orm/src/Proxy/ProxyFactory.php:279
$entityPersister = $this->uow->getEntityPersister($className);
$this->filterHash
of the BasicEntityPersister$parentEntity->getChildCollection()
so that it goes throughvendor/doctrine/orm/src/UnitOfWork.php:2702
$persister = $this->getEntityPersister($assoc->targetEntity);
->currentPersisterContext->rsm
instance of ResultSetMapping by calling the->addFieldResult
twice for each ChildEntity column. So theResultSetMapping->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 queryvendor/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 andvendor/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
.And a JSON formatted partial stack trace of the Exception:
The text was updated successfully, but these errors were encountered: