Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Serializer] use theNormalizerAwareInterface to prevent circular references#16826

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
xabbuh wants to merge1 commit intosymfony:4.4fromxabbuh:symfony-46471

Conversation

xabbuh
Copy link
Member

@xabbuhxabbuh changed the title[Serializer] do not depend on concrete NormalizerInterface implementations[Serializer] use the NormalizerAwareInterface to prevent circular referencesMay 27, 2022
@derrabus
Copy link
Member

This implementation would cause an infinite recursion because the serializer would inject itself as normalizer and dispatch the normalize call to our custom normalizer again.

@chalasr
Copy link
Member

chalasr commentedMay 27, 2022
edited
Loading

The infinite recursion can be avoided with this trick:https://symfonycasts.com/screencast/api-platform-security/normalizer-aware#avoiding-recursion-with-a-context-flan

mykbas reacted with thumbs up emoji

@mtarld
Copy link
Contributor

As written in theAPI Platform documentation, this way to do is actually working if adding a flag in the context.

@HeahDude
Copy link
Contributor

I guess we can close here and open a new PR to documentsymfony/symfony#46625.

@chalasr
Copy link
Member

@HeahDude Not sure actually :) This example is what prevents us from enabling the serializer panel by default as it builds on an autowired concrete class instead of an interface.

The alternatives I can think of:

  • Use the NormalizerAwareInterface as currently proposed (with the suggested context flag trick to avoid recursion)
  • Change the parameter type declaration fromObjectNormalizer toNormalizerInterface and add the config needed to make it gets theserializer.normalizer.object service injected

If we are not happy with both approaches, that probably means we need to work on adding a better way to giveObjectNormalizer capabilities to a userland normalizer (e.g. a trait or a more scoped interface)

HeahDude and mykbas reacted with thumbs up emoji

Copy link
Contributor

@maxheliasmaxhelias left a comment

Choose a reason for hiding this comment

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

As written in the API Platform documentation, this way to do is actually working if adding a flag in the context.

So we need to add a mention like the API P doc to explain the flag in context.

@chalasr
Copy link
Member

Thinking twice about this, I'd advocate for the explicit DI approach (second alternative in#16826 (comment))

mtarld reacted with thumbs up emoji

@javiereguiluz
Copy link
Member

What should we do with this PR? Merge, close or keep working on it? Thanks!

@OskarStarkOskarStark changed the title[Serializer] use the NormalizerAwareInterface to prevent circular references[Serializer] use theNormalizerAwareInterface to prevent circular referencesOct 26, 2022
@mtarld
Copy link
Contributor

I think it misses two things:

  1. Add a flag in a context to prevent infinite recursions (here, the normalizer will call himself infinitely)
  2. Maybe add an example to inject a specific implementation of a normalizer thanks to container configuration (here it'll call the chain normalizer)

At least one of these points should be done to prevent infinite recursion.
Either using a flag or injecting a specific implementation will solve that issue, but IMHO, both of these methods might be documented.

@xabbuh
Copy link
MemberAuthor

closing as I think this has been fixed in#19532

@xabbuhxabbuh closed thisFeb 27, 2024
@xabbuhxabbuh deleted the symfony-46471 branchFebruary 27, 2024 15:22
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@maxheliasmaxheliasmaxhelias requested changes

@mtarldmtarldmtarld approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
4.4
Development

Successfully merging this pull request may close these issues.

8 participants
@xabbuh@derrabus@chalasr@mtarld@HeahDude@javiereguiluz@maxhelias@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp