Skip to content

[Serializer] Remove normalizer cache in Serializer class #17140

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
Jan 12, 2016

Conversation

jvasseur
Copy link
Contributor

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

The serializer cache the normalizer/denormalizer to use based only on the class and format. But the supportsNormalization and supportDenormalization methods can decide based on the data passed leading to hard to find bugs when the serializer used a cached normalizer it shouldn't use.

@@ -40,8 +40,6 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
protected $encoder;
protected $decoder;
protected $normalizers = array();
protected $normalizerCache = array();
protected $denormalizerCache = array();
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a BC break. so it cannot be merged as-is in 2.3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, didn't see they were protected and not private. Should i just keep them or keep the logic that is filling them to ?

Copy link
Member

Choose a reason for hiding this comment

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

I'd say we should keep them but never fill them, and keep reading from them in case someone fills them with its own logic

@jvasseur jvasseur force-pushed the remove-normalizer-cache branch from 57f572d to c3c04f8 Compare December 29, 2015 19:19
@jvasseur
Copy link
Contributor Author

Updated to keep BC as suggested by @nicolas-grekas.

@xabbuh
Copy link
Member

xabbuh commented Dec 30, 2015

Can we add a test that would fail when the caching was added again to prevent regressions?

@nicolas-grekas
Copy link
Member

A meaningful test would be one implementing a (de)normalizer that uses the data as described above.

@jvasseur jvasseur force-pushed the remove-normalizer-cache branch 2 times, most recently from 8f21051 to 4ea7745 Compare January 3, 2016 17:03
@jvasseur jvasseur force-pushed the remove-normalizer-cache branch from 4ea7745 to 8566dc1 Compare January 3, 2016 17:08
@jvasseur
Copy link
Contributor Author

jvasseur commented Jan 3, 2016

Tests added.

@xabbuh
Copy link
Member

xabbuh commented Jan 3, 2016

👍

Status: Reviewed

@dunglas
Copy link
Member

dunglas commented Jan 11, 2016

👍

@dunglas
Copy link
Member

dunglas commented Jan 11, 2016

Btw, $context should be added as last argument of supportNormalization/supportDenormalization as well.

@@ -237,7 +237,6 @@ private function normalizeObject($object, $format = null, array $context = array
foreach ($this->normalizers as $normalizer) {
if ($normalizer instanceof NormalizerInterface
&& $normalizer->supportsNormalization($object, $format)) {
$this->normalizerCache[$class][$format] = $normalizer;
Copy link
Contributor

Choose a reason for hiding this comment

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

those properties should be annotated with @deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was planning to do a PR to master to deprecate them after this one is merged.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. 👍

@nicolas-grekas
Copy link
Member

👍

@Tobion
Copy link
Contributor

Tobion commented Jan 12, 2016

Thank you @jvasseur.

@Tobion Tobion merged commit 8566dc1 into symfony:2.3 Jan 12, 2016
Tobion added a commit that referenced this pull request Jan 12, 2016
…jvasseur)

This PR was merged into the 2.3 branch.

Discussion
----------

[Serializer] Remove normalizer cache in Serializer class

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

The serializer cache the normalizer/denormalizer to use based only on the class and format. But the supportsNormalization and supportDenormalization methods can decide based on the data passed leading to hard to find bugs when the serializer used a cached normalizer it shouldn't use.

Commits
-------

8566dc1 Remove normalizer cache in Serializer class
@jvasseur jvasseur deleted the remove-normalizer-cache branch January 12, 2016 13:08
This was referenced Jan 14, 2016
@fabpot fabpot mentioned this pull request Feb 3, 2016
nicolas-grekas added a commit that referenced this pull request Apr 19, 2016
This PR was squashed before being merged into the 3.1-dev branch (closes #18588).

Discussion
----------

[Serializer] Add deprecation notices

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #17140
| License       | MIT
| Doc PR        | none

As discussed in #18583, add deprecation notices to `master` instead.

Commits
-------

d3063ed [Serializer] Add deprecation notices
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.

6 participants