Skip to content

Add test for updating embedded relation using plain identifier #3145

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

Conversation

teohhanhui
Copy link
Contributor

@teohhanhui teohhanhui commented Oct 3, 2019

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #3133
License MIT
Doc PR N/A

Targeting 2.4 so that we're able to demonstrate that it works correctly on 2.4.

Background:

Before #3036, the $options we pass to the PropertyNameCollectionFactory was wrong, because it was using the (Serializer) $context directly. Specifically, the $context['groups'] were not translated to $options['serializer_groups'], so they had no effect. (There could have been many bugs caused by that.)

That bug fix however in turn revealed the problem with incorrect property metadata set on API resources in some projects (see for example #3133).

For example, the id property in the related resource is not in the serializer groups used for denormalization, which makes sense at first glance, because you don't want to allow updating the id. However, the ItemNormalizer uses the property metadata to identify the correct identifier property, so it's actually required that the id property must be part of the serializer groups used for denormalization (only applicable in the case of using plain identifiers, where you're sending the id property). To disallow updating the id, the correct solution is to use @ApiProperty(writable=false).

@teohhanhui teohhanhui requested review from dunglas and soyuka October 3, 2019 17:52
@teohhanhui teohhanhui force-pushed the test-update-embedded-relation-plain-id branch from bca96a0 to dfbb0d3 Compare October 3, 2019 18:03
@teohhanhui teohhanhui force-pushed the test-update-embedded-relation-plain-id branch from dfbb0d3 to b501e39 Compare October 3, 2019 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants