10000 LazyLoadingMetadataFactory looks broken by angelk · Pull Request #21538 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

LazyLoadingMetadataFactory looks broken #21538

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

Closed
wants to merge 4 commits into from

Conversation

angelk
Copy link
Contributor
@angelk angelk commented Feb 5, 2017
Q A
Branch? 3.2
Bug fix? no (tests only)
New feature? no
BC breaks? yes/no
Deprecations? no
Tests pass? no
License MIT

I'm expecting to have all parent classes in constraint group. By the [docs] (http://symfony.com/doc/current/validation/groups.html)

If you have inheritance (e.g. User extends BaseUser) and you validate with the class name of the subclass (i.e. User), then all constraints in the User and BaseUser will be validated. However, if you validate using the base class (i.e. BaseUser), then only the default constraints in the BaseUser class will be validated.

Testing with LazyLoadingMetadataFactory from v3.2.1 works fine.

@xabbuh
Copy link
Member
xabbuh commented Feb 7, 2017

This looks like it is caused by the changes done in #21053. I am not sure if your use case really makes much sense to be honest.

$factory = new LazyLoadingMetadataFactory($reader);
$metadata = $factory->getMetadataFor('Symfony\Component\Validator\Tests\Fixtures\EntityStaticCarTurbo');
$classMetaData = $metadata->getPropertyMetadata('wheels');
$constraints = $classMetaData[0]->getConstraints();
Copy link
Member

Choose a reason for hiding this comment

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

The culprit here is that you are making the assumption that getPropertyMetadata() of the ClassMetadata class will online return one PropertyMetadata instance (or that the one you need is the first entry in the returned collection). It's true that this was the case before #20793, but that IMO is can implementation detail you shouldn't rely on (the RecursiveContextualValidator, for example, iterates over the return property metadata). I'll see if we can nonetheless update the code to only return one instance, but as said that's not something I would rely on.

@angelk
Copy link
Contributor Author
angelk commented Feb 9, 2017

Hello,
I just updated the tests to iterate over constraints and groups.
Two groups are still missing in metadata - https://travis-ci.org/symfony/symfony/jobs/200139678#L3805

@fabpot
Copy link
Member
fabpot commented Feb 12, 2017

fabbot failures must be fixed.

@xabbuh
Copy link
Member
xabbuh commented Feb 12, 2017

Thank you for the failing test cases @angelk. I have reused them to revert the changes from #21053 in #21592. Closing here in favour of #21592.

@xabbuh xabbuh closed this Feb 12, 2017
fabpot added a commit that referenced this pull request Feb 13, 2017
…sses (angelk, xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[Validator] property constraints can be added in child classes

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21538, #21567
| License       | MIT
| Doc PR        |

This reverts the changes done in #21053 (and applies the test written by @angelk in #21538). I think trying to "fix" #15950 with the changes from #21053 was a mistake. Child classes should be able to refine validation constraints (I basically agree with @ro0NL's reasoning in #21567 (comment).

Commits
-------

9513a8a property constraints can be added in child classes
a266ff7 added test for staticClassLoader in LazyLoadingMetadatafactory
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.

5 participants
0