mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Proxy returns default value without initializing #5382
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 @Wilt on GitHub (Jan 12, 2017).
If we define a default value like this:
And we have a Proxy of
MyEntityinstead of an initialized entity then pulling the proxy method returns a default value without initializing the entity and resolving the actual database value.This means that the database value for
myColumnis actually holding a completely different value we got returned from our proxy without us realizing this.Since this way of defining default values is also mentioned in the documentation chapter: 3.2.2. How can I add default values to a column? we were very surprised that this issue occurred.
Are we doing something wrong here? Or is this a bug?
@Ocramius commented on GitHub (Jan 12, 2017):
@Wilt what code did you use to generate, retrieve and read the value from the proxy?
@Wilt commented on GitHub (Jan 12, 2017):
I am just checking once more....
I realize now that in this particular case I might have not used the
getterbut accessed the property directly. I will close and reopen if I am sure.I apologize...
@Ocramius commented on GitHub (Jan 12, 2017):
@Wilt accessing the property directly, if the property is
public, should still trigger lazy-loading. Can you check that, please?@Wilt commented on GitHub (Jan 12, 2017):
@Ocramius Yes, I got very confused and had a slight panic attack 😬
But it seems we are using a getter anyway, so I am not sure why it doesn't work as expected.
I need to leave now but tomorrow I will have a more in depth debug session and then I will report back to you. Thanks for your interest in the issue. Have a great evening/day (whatever timezone you are in).
@Ocramius commented on GitHub (Jan 12, 2017):
Reopening for you to provide feedback then :-)
@Wilt commented on GitHub (Jan 13, 2017):
We can't reproduce this issue. Probably a bad from our side.
I will close.
Thanks for your time and interest.
@Gappa commented on GitHub (Sep 9, 2021):
Google sent me here, I had the same problem:
$isPricelistwith the default value offalse.$entity->isPricelist()kept returningfalseeven for cases when it should have beentrue.Sadly, I was too quick with purging of the proxies directory, so I can't tell what was the exact problem. But I got the same behavior by removing all mentions of
isPricelistfrom the proxy class, so the getter calls the parent method directly without triggering an actual DB query for the real data.TLDR: The proxy file for the entity was outdated and needed to be refreshed.