-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Serializer tries to access initializer property when serializing a Doctrine Proxy object #44273
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
Comments
Can you please try the following patch? Does it help? --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php
+++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php
@@ -470,6 +470,10 @@ class PropertyAccessor implements PropertyAccessorInterface
throw $e;
}
} elseif (PropertyReadInfo::TYPE_PROPERTY === $type) {
+ if (!method_exists($object, '__get') && !\array_key_exists($name, (array) $object) && (\PHP_VERSION_ID < 70400 || !(new \ReflectionProperty($class, $name))->hasType())) {
+ throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not initialized.', $class, $name));
+ }
+
$result[self::VALUE] = $object->$name;
if (isset($zval[self::REF]) && $access->canBeReference()) {
|
Whether the patch fixes the issue or not, can you please try submitting a failing test case? That'd help a lot :) |
This patch did not fix the issue. I will try to provide a minimal reproduceable test tomorrow. Edit: I don't think |
While I'm working on the test case, I can confirm that reverting #44121 fixes the problem for me. |
It seems to be caused because calling if (! $realInstanceReflection->hasProperty($name)) {
$targetObject = $this;
$backtrace = debug_backtrace(false, 1);
trigger_error(
sprintf(
'Undefined property: %s::$%s in %s on line %s',
$realInstanceReflection->getName(),
$name,
$backtrace[0]['file'],
$backtrace[0]['line']
),
\E_USER_NOTICE
);
return $targetObject->$name;
} I don't have any better idea than checking if object implements |
@nicolas-grekas I created a minimal project to reproduce the error: https://github.com/IonBazan/serializer-proxy-bug |
Thanks for the reproducer. |
…s-grekas) This PR was merged into the 4.4 branch. Discussion ---------- [Serializer] fix support for lazy/unset properties | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #44273 #44283 | License | MIT | Doc PR | - This basically backports #43469 into 4.4, which is the way to go to fix #44273. The code that exists to handle uninitialized properties is broken anyway (it was before the recent changes.) Commits ------- db043aa [Serializer] fix support for lazy/unset properties
I get the same error with 6.3.0 with MongoDB ODM while pulling Document with User associated with referenceOne. Do you mind if we reopen the issue or should i create new issue ? @nicolas-grekas |
please open a new issue and provide an example application that allows to reproduce it |
Symfony version(s) affected
5.3.11
Description
After upgrading
symfony/serializer
from5.3.10
to5.3.11
Seralizer starts to access special$initializer<id>
property in proxies generated by Doctrine instead of letting the proxy initialize with actual objects.How to reproduce
Edit: Use this repository to reproduce: https://github.com/IonBazan/serializer-proxy-bug
When Serializing a Doctrine ODM document with
ReferenceMany
orReferenceOne
,PropertyAccessor
is trying to access a special$initializer<id>
property.Create 2 documents and make one of them reference the other. Now try to serialize the referencing document.
Following error should occur:
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: