-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NULL returned instead of collection after update to 2.14.0 #10376
Comments
As a suggested best practice, you should instantiate a default collection in your entity's constructor to ensure it has a valid state before it's persisted. Not knowing how your test works, at the bare minimum, a |
I'm actually getting the same, and on my constructor I'm setting an ArrayCollection, but the lazy proxy is returning null instead on my test and strict type failed.
The upgrade was suggested by dependabot but tests started failing. The issue happens after the data is persisted, the proxy seems unable to fetch the right data or when it does the data is not what it is in the database, so something must be blocking it to properly initialise -- that would be my guess. |
Hey @mbabker. |
There is a possibility your issues or at least one of those is fixed by #10362. It could be helpful if you try those changes on your tests. |
@simonberger it sounds like it does fix the current issue -- I just tried to manually load the data after using fixtures on my test and the test passed. So between loading fixtures and using it through proxies it fails, all proxy data is empty, only have id, rest of the fields are empty. Thanks for all your work everyone 👌 |
Yes I expected the problem to be your private id field which the PR fixes. In case someone fights the problem a workaround can also be the change the visibility of the identifier to protected. |
I was also able to solve the issue. In my case I lost the data below the initial object (lazy loading?) by decomposing to much the object... so this is why the result was NULL. Not sure if I shall close this ... at least my solution is a work around.... But at the end this new version created an issue that might need to be solved on doctrine's side. |
If the problem is solved for you, feel free to close. But if we should accept it as a bug, we need a stable reproducer or a failing test. A reproducer would be a repository that I can check out and execute in order to reproduce your problem. |
So, I will close this item as I was not able to produce a failing specimen. |
Is it possible that this issue is related to #10336 ? I had the same behavior : using my fixtures just after they were initialized everything was fine but as soon as I started a functional test (EM::clear() is called), I got this error. Not on collection though but on standard property which were not initialized properly somewhere. I downgraded to doctrine/orm:2.13.5 for now waiting for the next release. |
@DigitalTimK did I get it right that you intended to close this issue? |
@mpdude yes, that correct. |
Just for information, this happened to me with ORM 2.9.5 after upgrading from php 7.4 to php 8.1 and after debugging, it seems that there was an "invalid mapping" exception that was silently thrown here: https://github.com/doctrine/orm/blob/2.16.x/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php#L269 The reason is that one of my entity's relation, was implementing JsonSerializable, but didn't have a return type. Which threw this error:
I had to add a return type to And that fixed my Collection being null problem |
BC Break Report
Summary
After
composer update "doctrine/orm"
I have an error during my phpunit (v9.5.27) tests. The returned value (children) isnull
instead of an collection.Previous behavior
tests are running w/o error
Current behavior
Tests raise an error:
TypeError: App\Entity\Pricing::getDiscounts(): Return value must be of type Doctrine\Common\Collections\Collection, null returned
How to reproduce
This error seems to be happen only during PHPUNIT-test. I encounter no issue when calling this function in a controller or in twig.
The text was updated successfully, but these errors were encountered: