Skip to content

[Serializer] fix support for lazy/unset properties #44295

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

Merged
merged 1 commit into from
Nov 28, 2021

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 26, 2021

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.)

try {
$attributeValue = $this->getAttributeValue($object, $attribute, $format, $context);
} catch (AccessException $e) {
if (sprintf('The property "%s::$%s" is not initialized.', \get_class($object), $attribute) === $e->getMessage()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than detecting the error message (which could easily be broken if we reword the message, especially as there is no tests covering this), shouldn't we use a subclass of the AccessException instead ?
The rule until now is that the exception messages are not covered by any BC rules and should not be relied upon to catch exceptions.
And this is a cross-component dependency, which would require actually changing the BC rules to allow the current pattern

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree, that's what we've done on 5.3 already, but introducing a new class in 4.4 doesn't look like a good idea to me...

@nicolas-grekas nicolas-grekas merged commit dc04b8c into symfony:4.4 Nov 28, 2021
@nicolas-grekas nicolas-grekas deleted the ser44 branch November 28, 2021 18:07
This was referenced Nov 29, 2021
This was referenced Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants