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

Skip to content

update 3.2->3.3 bc break: decoration of validator.validator_factory service is not working #24222

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
Strate opened this issue Sep 15, 2017 · 9 comments

Comments

@Strate
Copy link
Contributor

Strate commented Sep 15, 2017

Q A
Bug report? yes
Feature request? no
BC Break report? yes
RFC? no
Symfony version 3.3.9

I do have a decorator service over validator.validator_factory, as described in documentation. It is not working for now, because:

  1. \Symfony\Component\DependencyInjection\Compiler\DecoratorServicePass is removing original service, renaming it to my_service_name.inner and set alias from my_service_name to validator.validator_factory.

  2. After that \Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass is invoked, and tries to locate original service validator.validator_factory which can not be found anymore.

As a result, validator factory built with wrong dependencies.

@xabbuh
Copy link
Member

xabbuh commented Sep 15, 2017

Can you confirm that the change from #24223 applied on the compiler pass in your code base solves the issue?

@Strate
Copy link
Contributor Author

Strate commented Sep 18, 2017

@xabbuh thank you for participating, but, unfortunatelly, that fix does not help.

Changing getDefinition to findDefinition forces AddConstraintValidatorsPass to find decorator service, not a decorated service. As a result, compiler pass replaces argument on a decorator (custom class, which expects to original service as a first argument), not on original service.

@stof
Copy link
Member

stof commented Sep 18, 2017

The issue is that the AddConstraintValidatorPass is registered as TYPE_BEFORE_REMOVING, which runs after the decoration.

Btw, this can also cause other bugs, because it also runs after optimizations while it is adding new links in the graph, which may forbid some optimizations already applied.
@fabpot you are the one moving it later in #20116. Why was it done ?

@Strate
Copy link
Contributor Author

Strate commented Sep 18, 2017

@stof I am also often register my passes as TYPE_BEFORE_REMOVING, because I am often experience an issue, when service tries to collect other services before they appears in container.

For example, I have own "autowire" pass, which registers new services in TYPE_BEFORE_OPTIMIZATION stage, and, depends on bundles order, collecting by tags pass runs before "autowiring" pass. So, I forced to move my collecting pass later, to TYPE_OPTIMIZE or TYPE_BEFORE_REMOVING

So, maybe we could have TYPE_COLLECT_TAGS stage?

@Strate
Copy link
Contributor Author

Strate commented Sep 21, 2017

So, currently I solved the issue by writing custom CompilerPass, which performs decoration on TYPE_BEFORE_REMOVING stage (my bundle registered after FrameworkBundle, so it helps). Btw, issue still exists.

@stof
Copy link
Member

stof commented Sep 26, 2017

@Strate if you add new references after the optimizations, you may break your container entirely due to optimizations being wrong.

What you should do is register your "autowire" pass creating new services with a priority higher than 0, so that it runs at the beginning of TYPE_BEFORE_OPTIMIZATION stage.

@Strate
Copy link
Contributor Author

Strate commented Sep 26, 2017

@stof default \Symfony\Component\DependencyInjection\Compiler\AutowirePass is registered in TYPE_OPTIMIZE stage, is it okay?

Btw, I think we need to document it.

@xabbuh
Copy link
Member

xabbuh commented Oct 11, 2017

@fabpot Can you answer @stof's question from #24222 (comment)? :)

@fabpot
Copy link
Member

fabpot commented Oct 11, 2017

@xabbuh @stof I don't remember, sorry.

fabpot added a commit that referenced this issue Feb 13, 2019
…ations (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[FrameworkBundle] add constraint validators before optimizations

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

Commits
-------

05e0e16 add constraint validators before optimizations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants