Skip to content
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

ContextBuilder called twice for normalization context #6693

Open
maxhelias opened this issue Oct 5, 2024 · 3 comments
Open

ContextBuilder called twice for normalization context #6693

maxhelias opened this issue Oct 5, 2024 · 3 comments

Comments

@maxhelias
Copy link
Contributor

API Platform version(s) affected: 3.4

Description
During the runtime of a request on my app, I noticed that my ContextBuilder::createFromRequest was called 2 times to create the normalization context :

How to reproduce
Create a ContextBuilder or check out ContextBuilder's built-in

Possible Solution
I was wondering if we can in the SerializeProcessor, check whether the request attribute _api_normalization_context is already computed or not, to avoid a second call.
Normally the context calculation shouldn't change in the same runtime, but I may be missing something.

Additional Context
This may be intentional, in which case, another solution might be considered to leave the possibility of recomputing/caching or not the normalization context at the operation level or elsewhere to leave the choice to the user if a recomputing is necessary

@soyuka
Copy link
Member

soyuka commented Oct 7, 2024

Sometimes read is not called (on POST operations for example). But indeed, we may add a check and use the previously computed context.

@maxhelias
Copy link
Contributor Author

Oh yes, thanks, i had in mind the read option on the operation but had forgotten about it.
The legacy system with listeners does the same thing. I'll do a PR soon for both 😉

@soyuka
Copy link
Member

soyuka commented Oct 7, 2024

👍 you can target 3.4

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

No branches or pull requests

2 participants