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

Fix #19943 Make sure to process each interface metadata only once#20078

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

Conversation

@lemoinem
Copy link
Contributor

@lemoinemlemoinem commentedSep 28, 2016
edited
Loading

QA
Branch?2.7+
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#19943
LicenseMIT
Doc PRN/A

Here is the fix for#19943, If you haveInterfaceA <- InterfaceB <- Class with a constraint on a method defined onInterfaceA, the constraint and its eventual violations are currently validated and reported twice.

Copy from#19943 (comment):
As far as I can see, the problem seems to arise inLazyLoadingMetadataFactory:

ReflectionClass::getInterfaces() returns both interfaces implemented directly and through inheritance (either through another interface or through a parent class). In the end, the following process occurs:

  1. PriceInterface is parsed and itsNotBlank constraint onvalue is loaded
  2. VariablePriceInterface is parsed and inheritsPriceInterface's constraints (which is OK).
  3. ProductPrice is parsed and inherits bothPriceInterface andVariablePriceInterface's constraints, which leads to a duplicatedNotBlank constraint, one from each Interface.

The Best Way ™️ would be to be able to extract the list of interfaces implemented by a class directly only. However, the process seems a bit intricate... I will start working on it and prepare a PR to that effect. However, if any of you has a better idea, I'm all hears...

TODO:

  • Regression tests to make sure the bug doesn't reappear

@HeahDude
Copy link
Contributor

The label "BC break" should be removed. With some tests it would be 👍 , thanks!

@lemoinemlemoinemforce-pushed thefix/validator/19943-interface-metadata-double-processing branch 2 times, most recently fromc23bc3b toa696f42CompareSeptember 28, 2016 21:32
@lemoinem
Copy link
ContributorAuthor

lemoinem commentedSep 28, 2016
edited
Loading

@HeahDude Yes, the label has been added by mistake, I made an error with the PR template... And I can't seem to be able to remove it ;).

Here are the tests, I had to add an Interface so the use case would be adequately represented. I double checked, the tests fail without the patch. I think I'm good for the full review.

The failed tests on appveyor and travis concern the Twig Bridge and Bundle or the SecurityBundle. It's unrelated to this PR.

Status: Needs Review

@lemoinemlemoinem changed the title[WIP] Fix #19943 Make sure to process each interface metadata only onceFix #19943 Make sure to process each interface metadata only onceSep 28, 2016
* @Assert\Callback({"Symfony\Component\Validator\Tests\Fixtures\CallbackClass", "callback"})
*/
class Entityextends EntityParent
class Entityextends EntityParentimplements EntityInterface, EntityParentInterface
Copy link
Contributor

@HeahDudeHeahDudeSep 28, 2016
edited
Loading

Choose a reason for hiding this comment

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

I think you should add another interface likeOtherEntityInterface (I don't really like the name but you got the point), because implementing both interfaces when one extends another does not make sense, this PR is not trying to fix that case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or just add theEntityParentInterface to theEntityParent instead :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yes... I guess I see your point. Although the fix is going to take care of this case too.

I also added the interface on theEntityParent this case (interface implemented through class inheritance) was already taken care of in the code before my patch, but not in the test. I'll add (yet) another interface to take care of this.

Copy link
ContributorAuthor

@lemoinemlemoinemSep 28, 2016
edited
Loading

Choose a reason for hiding this comment

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

If I addedEntityParentInterface toEntityParent would not have solved the issue because I had added theEntityInterface to it too. I think the new version is better.

@lemoinemlemoinemforce-pushed thefix/validator/19943-interface-metadata-double-processing branch froma696f42 to422ca4eCompareSeptember 28, 2016 22:18
@lemoinem
Copy link
ContributorAuthor

@HeahDude I updated the tests to take into account your comments. Thanks for the feedback. The interfaces are now namedEntityInterfaceA andEntityInterfaceB. I think that's the cleanest way to go for Test Fixtures...

constCLASSNAME ='Symfony\Component\Validator\Tests\Fixtures\Entity';
constPARENTCLASS ='Symfony\Component\Validator\Tests\Fixtures\EntityParent';
constINTERFACECLASS ='Symfony\Component\Validator\Tests\Fixtures\EntityInterface';
constINTERFACEACLASS ='Symfony\Component\Validator\Tests\Fixtures\EntityInterfaceA';
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add some underscores to constants names to ease readability, I know you did it for consistency because there weren't any but since you add some more, and longer ones with single-lettered meanings... I think maybe we could start using them :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yup, good point. Here you go.

@lemoinemlemoinemforce-pushed thefix/validator/19943-interface-metadata-double-processing branch from422ca4e toa59f2a5CompareSeptember 28, 2016 22:36
@lemoinemlemoinemforce-pushed thefix/validator/19943-interface-metadata-double-processing branch froma59f2a5 to2f9b65aCompareSeptember 28, 2016 22:39
@HeahDude
Copy link
Contributor

HeahDude commentedSep 29, 2016
edited by javiereguiluz
Loading

LGTM 👍, thanks!

Status: Reviewed

Failures unrelated and should now be fixed by#20079.

@fabpot
Copy link
Member

Thank you@lemoinem.

@fabpotfabpot merged commit2f9b65a intosymfony:2.7Sep 30, 2016
fabpot added a commit that referenced this pull requestSep 30, 2016
…ly once (lemoinem)This PR was merged into the 2.7 branch.Discussion----------Fix#19943 Make sure to process each interface metadata only once| Q             | A| ------------- | ---| Branch?       | 2.7+| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#19943| License       | MIT| Doc PR        | N/AHere is the fix for#19943, If you have `InterfaceA <- InterfaceB <- Class` with a constraint on a method defined on `InterfaceA`, the constraint and its eventual violations are currently validated and reported twice.Copy from#19943 (comment):As far as I can see, the problem seems to arise in [`LazyLoadingMetadataFactory`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php#L117-L123):[`ReflectionClass::getInterfaces()`](http://php.net/manual/en/reflectionclass.getinterfaces.php) returns both interfaces implemented directly and through inheritance (either through another interface or through a parent class). In the end, the following process occurs:1. `PriceInterface` is parsed and its `NotBlank` constraint on `value` is loaded2. `VariablePriceInterface` is parsed and inherits `PriceInterface`'s constraints (which is OK).3. `ProductPrice` is parsed and inherits both `PriceInterface` and `VariablePriceInterface`'s  constraints, which leads to a duplicated `NotBlank` constraint, one from each Interface.The Best Way ™️ would be to be able to extract the list of interfaces implemented by a class directly only. However, the process seems a bit intricate... I will start working on it and prepare a PR to that effect. However, if any of you has a better idea, I'm all hears...TODO:- [x] Regression tests to make sure the bug doesn't reappearCommits-------2f9b65aFix#19943 Make sure to process each interface metadata only once
This was referencedOct 3, 2016
@lemoinemlemoinem deleted the fix/validator/19943-interface-metadata-double-processing branchMay 4, 2017 00:27
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@HeahDudeHeahDudeHeahDude requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@lemoinem@HeahDude@fabpot@javiereguiluz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp