Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] Revert deprecation of ContextAwareEncoderInterface and ContextAwareDecoderInterface #47150

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
merged 1 commit into from
Aug 21, 2022

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Aug 2, 2022

Q A
Branch? 6.1
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

While reviewing #43231, I figured out that the correct fix for #38270 was to make ChainEncoder properly consider ContextAwareEncoderInterface when deciding to cache or not.

Since this interface is useful to discriminate the cache/no-cache situations, we have to undeprecate it (from #43982.)

/cc @Guite and @mtarld FYI

@chalasr
Copy link
Member

chalasr commented Aug 2, 2022

Since this interface is useful to discriminate the cache/no-cache situations, we have to undeprecate it.

I'm not sure about this given these interfaces were just about surcharging the method signatures with an extra $context argument, which has been moved to the parent interfaces when deprecating them so normalizers/encoders methods always take care of the context. Undeprecating would be one step backward regarding the component API. I think we need something else for the issue at hand, as we do want to get rid of these interfaces.

@nicolas-grekas
Copy link
Member Author

If we pass a context to supports method, we have to consider that context can be taken into account, aka we have to remove the cache. Adding yet another interface for cacheable supports feels like renaming interface for the sake of it. Until 6.1, supports method were expected to receive only one argument, the format. That made them cacheable. ContextAware interfaces were here to tell that the context could be used, and we forgot to make those instances uncacheable. I feel like we already have everything in place to properly deal with the issue.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Aug 2, 2022

(Note that I would go one step further in 6.2 and deprecate passing the $context argument to implementations that don't declare ContextAware*Interface.)

@chalasr
Copy link
Member

chalasr commented Aug 2, 2022

That would be a big code smell to me, really. ContextAware*Interface don't include a single word about caching, it's not its purpose but a side effect. Undeprecating these interfaces 3 months later for that abused usage does not feel right.

Adding yet another interface for cacheable supports feels like renaming interface for the sake of it

Caching support is a different feature, making it explicit would not be a bad thing imho.

(Note that I would go one step further in 6.2 and deprecate passing the $context argument to implementations that don't declare ContextAware*Interface.)

But we did that change for a reason, mainly usability. Pretty much all implementations want the context (not always for caching, I'd even say it's the minority), and they end up implementing those interfaces for that just because we weren't able to add a new method parameter to an existing interface at that time, which added some extra complexity for the developer.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Aug 2, 2022

That would be a big code smell to me, really. ContextAware*Interface don't include a single word about caching, it's not its purpose but a side effect. Undeprecating these interfaces 3 months later for that abused usage does not feel right.

On the contrary: the possibilty of caching is a consequence of the design. A design should not be tailored to any specific use case (eg caching). Instead, proper design should lead to abstractions that empower end users to do what they need. Eg caching.

Caching support is a different feature, making it explicit would not be a bad thing imho.

See my previous note.

But we did that change for a reason, mainly usability. Pretty much all implementations want the context (not always for caching, I'd even say it's the minority), and they end up implementing those interfaces for that just because we weren't able to add a new method parameter to an existing interface at that time, which added some extra complexity for the developer.

None of the core encoders use the context to decide in supportsEncoding.
The reason we did it was ignoring a design reason, exactly like we ignored #43231 for so long while the issue was valid.
Planning for a less capable abstraction is not an improvement...

@chalasr
Copy link
Member

chalasr commented Aug 2, 2022

I'm sorry but I disagree. These interfaces were not meant to add any behavior but to allow some various metadata to transit, which is something that almost any encoder/normalizer need hence it is not worth such a dedicated abstraction which appears to be annoying to most. Applications using the serializer usually have custom encoders and normalizers so it's not only impacting the built-in ones.
I would really prefer an other approach such as the one mentioned in the linked PR so I'm -1 here

@nicolas-grekas
Copy link
Member Author

Relying on ContextAware*Interface is the legit way to fix #38270, thus it's how we should fix it in 4.4+. Not fixing this issue in 4.4 because we'd like another API in 6.2 doesn't sound reasonable to me. If these interfaces are used in 4.4 to deal with the caching issue (as enabled by the abstraction), then the deprecation in 6.1 is plain broken since it deprecates an API without providing any viable alternative. This is certainly not the desired outcome as that puts ppl into a dead-end.

Undeprecating in 6.1 is a must to me.

If we like to re-deprecate in 6.2, we must do so while providing a viable alternative.

@chalasr
Copy link
Member

chalasr commented Aug 2, 2022

Undeprecating in 6.1 is a must to me.

And deprecating is a must to me... which I'd prefer not doing twice for obvious reasons.
The bug at hand does not seem to impact much people given the small number of reactions on the issue so maybe it's part of why no one provided a fix.
Anyway, please consider putting this PR on hold so that we can look for alternatives that do not involve to rollback on a good deprecation we all agreed on just because it eventually allows us to fix a bug. I'll be back from vacation next week so I'm going to try finding one.

Linking to #43982 btw to know about these interfaces purpose and the motivation behind removing them.

@dunglas
Copy link
Member

dunglas commented Aug 2, 2022

I also prefer introducing a new dedicated interface instead of re-introducing this hacky interface that I introduced initially to fix an older bad design choice that was annoying for many use cases.

@chalasr
Copy link
Member

chalasr commented Aug 21, 2022

Thanks for your patience and your consideration on the fact that deprecating these interfaces comes with relevant motivations.
I'm ok to merge this as long as we agree it is only temporary, for the time needed to implement a proper solution for encoders to opt-in into caching, which could be the same as the one we have for normalizers (and potentially just use the very same interface modulo the \Normalizer sub-namespace). I will work on this, hopefully for 6.2.

@chalasr
Copy link
Member

chalasr commented Aug 21, 2022

Thank you @nicolas-grekas.

@chalasr chalasr merged commit f8ed3ce into symfony:6.1 Aug 21, 2022
chalasr added a commit that referenced this pull request Aug 21, 2022
…n ChainEncoder/ChainDecoder (Guite)

This PR was merged into the 4.4 branch.

Discussion
----------

[Serializer] Fix caching context-aware encoders/decoders in ChainEncoder/ChainDecoder

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #38270
| License       | MIT
| Doc PR        | -

As proposed in #43231 (comment)
Will require #47150 on 6.1 until a proper solution is implemented, hopefully in 6.2.

Commits
-------

5902380 [Serializer] Fix caching context-aware encoders/decoders in ChainEncoder/ChainDecoder
@fabpot fabpot mentioned this pull request Aug 26, 2022
@nicolas-grekas nicolas-grekas deleted the ser-context-aw branch August 31, 2022 09:14
chalasr added a commit that referenced this pull request Sep 21, 2022
This PR was merged into the 6.1 branch.

Discussion
----------

remove upgrade instructions leftovers of #47150

| Q             | A
| ------------- | ---
| Branch?       | 6.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

This PR corrects that #47150 has not been reflected in the UPGRADE doc.

Commits
-------

dc07bdf remove wrong entries for #47150
chalasr added a commit that referenced this pull request Sep 21, 2022
* 6.1:
  remove wrong entries for #47150
  Fix LocaleListenerTest Accept-Language headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants