mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Trying to access array offset on value of type null in BasicEntityPersister #7111
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @armellin on GitHub (Feb 17, 2023).
Bug Report
Summary
In Persisters/Entity/BasicEntityPersister.php:1727 there is an access to $assoc['isOwningSide'] but $assoc may be null:
Current behavior
Validating an Entity with a ManyToMany association, I got that error.
@mpdude commented on GitHub (Feb 19, 2023):
Thank you for the bug report!
To help us reproduce this, could you try to provide the two entities in questions (those with the relationship between each other) and reduce them to the minimum amount of code that still causes the error?
My guess would be that you can remove all methods and fields except the IDs and the association.
There were no recent relevant changes in that area of the code. I am suspecting some kind of misconfiguration. Anyways, we should spot that and give a helpful error message, not fail with an error like this.
@armellin commented on GitHub (Feb 19, 2023):
I have the same suspicion, especially because all other associations work perfectly. Digging more I have found that it's caused by:
in the entity which is the owning side of the ManyToMany association with the Product entity.
If I cut the "products" away from the fields list, everything works.
Before testing more, is it supported to have a ManyToMany association in the UniqueEntity constraint?
@mpdude commented on GitHub (Feb 20, 2023):
You have not provided any entity code, configuration or stack traces yet, which makes it difficult for others to understand the situation.
If you think it’s related to a
UniqueEntityconstraint (which might be confirmed by a stack trace), that seems to be a Symfony thing and you’d need to ask over at their repo.@armellin commented on GitHub (Feb 20, 2023):
Ok, thanks.
But, anyway, shouldn't we test if $assoc is not null (which might be, according to the method's signature) before accessing $assoc['isOwningSide'] ?
Or is it overengineering?
Feel free to close this issue if you think that it's not necessary.
@mpdude commented on GitHub (Feb 20, 2023):
I agree we should, but probably it can not be more than a generic
InvalidArgumentExceptionin that place.The parameter is passed through a lot of methods apparently (and the same pattern/problem might occur elsewhere?). To give a more meaningful exception message, we probably have to find a suitable place higher up?
@AnthonyANI commented on GitHub (Apr 26, 2023):
I'm running into this same bug with BasicEntityPersister. It is indeed reproduced by UniqueEntityValidator for validating a constraint on a Collection/ManyToMany which calls default repository method findBy() to do so.
Line 1724 in BasicEntityPersister is using $assoc when it seems it should be using $association as $assoc is null (which is valid per the method signature as mentioned by @armellin) and $association isn't and has the 'isOwningSide' key and value ready for use. @mpdude Is that intentional? Thanks!


This is what's passed to findBy() of EntityRepository and loadAll() of BasicEntityPersister:

From there, loadAll() of BasicEntityPersister passes a null to $assoc (default null), which plays out to the error.


Full callstack if you need it:
@wizzyto12 commented on GitHub (Aug 23, 2023):
I have the same issue.
@apastorsales commented on GitHub (Aug 25, 2023):
I have the same issue.
@FlyingDR commented on GitHub (Dec 1, 2023):
@mpdude I've faced the same issue trying to use
\Doctrine\ORM\EntityRepository::findBy()with the$criteriathat references many-to-many association.Relevant parts of entities:
Table.php
Mode.php
Code that produces the issue:
findBy()callsloadAll()withnullfor$assocargument and thisnullis passed down to the location, mentioned in the issue description.Stack for the issue is:
From the Git history, it can be seen, that the code that caused the issue was added by https://github.com/doctrine/orm/pull/1249, but it was a long time ago.
There is possibly another issue at the same place:
23d36c0d52/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php (L1745-L1752)If the condition on the line 1745 is true then there will be
TypeErrorin line 1749 because of a type mismatch:23d36c0d52/lib/Doctrine/ORM/Mapping/QuoteStrategy.php (L49)From the local context at the place of the issue, it looks like the real issue is the idea of passing the
$assocargument to this method at all.getSelectConditionStatementColumnSQL()method is only called from thegetSelectConditionStatementSQL()and it is only used for many-to-many associations. Also, by the time of using the$assocargument the association for it is already resolved in the$associationfield.What is interesting is that in 3.x branch affected code includes assertion, so it will result in
AssertionErrorinstead of warning:f8ced51687/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php (L1655)@samharvey44 commented on GitHub (Dec 8, 2023):
As above, also experiencing this error - it seems to occur when attempting a
findByorfindOneByon aManyToManyrelationship with no inverse relation.@jklmnop commented on GitHub (Feb 7, 2024):
Also experiencing this.
@mateusfmello commented on GitHub (Feb 26, 2024):
I'm also having the same problem with
Doctrine version:
2.9@karrakoliko commented on GitHub (Apr 24, 2024):
Experiencing the same when trying to use Criteria with
containsexpression.Product.php:
Category.php:
Criteria:
Call:
Error:
@mateusfmello commented on GitHub (Apr 29, 2024):
My code is exactly like this, same relationship and this error also occurs.
Doctrine version:
2.19.3@karrakoliko commented on GitHub (Apr 29, 2024):
Actually, solution is to use product repository's query builder.
some
ProductRepositorymethod:There must be a more clear error message though.
Is error happens because of relation join clause not added?
@mateusfmello commented on GitHub (Apr 29, 2024):
I don't know why this happens, I haven't investigated the problem yet, I'll try your approach today if possible, after testing I'll get back to you for feedback.
@mateusfmello commented on GitHub (Apr 29, 2024):
$queryis$qb?Because
$qbdoes not have theexecutemethod@mateusfmello commented on GitHub (Apr 29, 2024):
@karrakoliko This solution is not ideal for me, because in my case I have clients and groups, where a client can have many groups and groups can have many clients, and I use the limit 5 for clients, so the result is less than 5 clients, because Some of the clients have more than one group, so the query result repeats clients, but with different groups.
Table
clientsTable
groupsTable
clients_groupsQuery result returns only 3 clients, but what was expected was 5, where the client with id 1 returned with 3 groups