Skip to content

Fix initialization of the serialization context #1726

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

Conversation

meyerbaptiste
Copy link
Member

@meyerbaptiste meyerbaptiste commented Feb 22, 2018

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

According to

$context['normalization_context'] = $this->serializerContextBuilder->createFromRequest($request, true, $attributes);
, the normalization context array is in the normalization_context index of the context array. So, if we pass the whole context array to the EagerLoadingExtension::joinRelations() method, we can't properly retrieve groups, max depth and attributes.

@meyerbaptiste
Copy link
Member Author

Okay, it doesn't work in the case of deserialization... I'll investigate.

@meyerbaptiste
Copy link
Member Author

meyerbaptiste commented Feb 22, 2018

I think we should fix this in the ReadListener class instead, like that it should work with deserialization too.
Indeed, when we call IriConverterInterface::getItemFromIri() during deserialization for example, the denormalization context is at first level in the context array and not in a denormalize_context index.

- $context['normalization_context'] = $this->serializerContextBuilder->createFromRequest($request, true, $attributes);
+ $context += $this->serializerContextBuilder->createFromRequest($request, true, $attributes);

But it looks like a BC Break to remove this key, isn't it?

WDYT @api-platform/core-team?

@soyuka
Copy link
Member

soyuka commented Feb 22, 2018

+1 about the second option. I'm not sure that this context is exposed to the public, I mean isn't it an internal thing only?

@meyerbaptiste
Copy link
Member Author

Huum, not really. It's exposed when you implement ContextAwareQueryCollectionExtensionInterface and ContextAwareCollectionDataProviderInterface for example...

@dunglas
Copy link
Member

dunglas commented Feb 22, 2018

👍 for the second option. It's kinda internal and it has been introduced in 2.2. It's now or never...

@meyerbaptiste meyerbaptiste force-pushed the fix_normalization_context_eager_loading_extension branch from befd9ba to 6b85e58 Compare February 22, 2018 22:05
@meyerbaptiste meyerbaptiste changed the title Fix the normalization context passed to EagerLoadingExtension::joinRelations() Fix initialization of the serialization context Feb 22, 2018
@meyerbaptiste meyerbaptiste force-pushed the fix_normalization_context_eager_loading_extension branch 2 times, most recently from 5d9fc1f to 37a3b72 Compare February 23, 2018 09:24
@soyuka
Copy link
Member

soyuka commented Feb 23, 2018

needs to target 2.2 as a bug fix then?

@meyerbaptiste
Copy link
Member Author

meyerbaptiste commented Feb 23, 2018

Right, I missed this branch...

@meyerbaptiste meyerbaptiste changed the base branch from master to 2.2 February 23, 2018 09:43
@meyerbaptiste meyerbaptiste force-pushed the fix_normalization_context_eager_loading_extension branch from 37a3b72 to eb12404 Compare February 23, 2018 09:45
@dunglas dunglas merged commit 52670e5 into api-platform:2.2 Feb 23, 2018
@dunglas
Copy link
Member

dunglas commented Feb 23, 2018

Thanks @meyerbaptiste

@meyerbaptiste meyerbaptiste deleted the fix_normalization_context_eager_loading_extension branch February 23, 2018 13:22
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.

3 participants