-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Fix serialized path for non-scalar values #49525
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
nicolas-grekas
merged 1 commit into
symfony:6.2
from
boenner:serializer-serializedpath-with-non-scalar-types
Mar 31, 2023
Merged
[Serializer] Fix serialized path for non-scalar values #49525
nicolas-grekas
merged 1 commit into
symfony:6.2
from
boenner:serializer-serializedpath-with-non-scalar-types
Mar 31, 2023
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hey! I think @ThomasNunninger has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
561df12
to
d82ec41
Compare
nicolas-grekas
approved these changes
Mar 31, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the code to preserve the order.
Thank you @boenner. |
Merged
nicolas-grekas
added a commit
that referenced
this pull request
Apr 14, 2023
…kalineskou) This PR was merged into the 6.2 branch. Discussion ---------- [Serializer] Fix serializer normalize attribute context | Q | A | ------------- | --- | Branch? | 6.2 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the latest branch. - For new features, provide some code snippets to help understand usage. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Before 6.2.8 property attribute`#[Context(normalizationContext: [AbstractObjectNormalizer::SKIP_NULL_VALUES => true])]` was working correctly Before this PR #49525 `updateData` was using the `$attributeContext` but it got changed to using `$context` (which ignored the attribute context) Fixed the `testNormalizeUsesContextAttributeForPropertiesInConstructorWithSerializedPath` test also since `Context` attribute class was never used in the file (the date was still in `d-m-Y` format when the format key was `m-d-Y`) Would have ported it to 5.4, but it was not added in that branch. Latest commit for this file in 5.4 https://github.com/symfony/symfony/blob/6ae4ac9b9f46203b3ebae3c4c52edd546709bdb1/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php#L205 Commits ------- 942a184 Fix serializer normalize attribute context
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This relates to #49494 and #49225. When non-scalar values are normalized, they are normalized twice in the
normalize()
function:and a bit later:
For non-scalar values with a
SerializedPath
annotation this leads to an exception because the serializer is trying to re-populate the path. RunningupdateData()
only once fixes this, but breaks a couple of tests across the components as it changes the order of elements in the serialized string (non-scalar values will be pushed to the end). Other than the string comparisons, nothing seems to break. This was also an issue while reviewing the PR for theSerializedPath
annotation (#43534 (comment)) and got reverted because of the potential BC break.I'm not sure what benefit normalizing twice brings, so I added the test from @HonzaMatosik, changed the behavior in the normalizer and fixed the broken tests. If that's not the preferred solution here, I'd be ok with just eleminating the "The element you are trying to set is already populated" exception in the
SerializedPath
and allow overwriting values.