Skip to content

[DI] Service locators can't be decorated #33670

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

Conversation

malarzm
Copy link
Contributor

@malarzm malarzm commented Sep 23, 2019

Q A
Branch? 4.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets n/a
License MIT
Doc PR n/a

This popped up while I was trying to update my work project as we have decorated the messenger.receiver_locator service. Not sure if this is a regression in DI or a change in messenger that caused the issue thus I'm not marking this as a BC break.

Exception while trying to compile the container:

Invalid definition for service "Symfony\Component\DependencyInjection\Tests\Compiler\DecoratedServiceLocator": an array of references is expected as first argument when the "container.service_locator" tag is set.

Expected result: service locator can be decorated.

@nicolas-grekas
Copy link
Member

Would you mind investigating what the fix could be?

@malarzm
Copy link
Contributor Author

malarzm commented Sep 26, 2019

I'm not familiar with DI internals but can give it a shot in upcoming days :)

@malarzm malarzm force-pushed the service-locator-cant-be-decorated-mm branch 2 times, most recently from 3a48003 to d20d9a7 Compare October 5, 2019 11:33
@malarzm
Copy link
Contributor Author

malarzm commented Oct 5, 2019

@nicolas-grekas bugfix is ready, travis is happy :)

@malarzm malarzm changed the base branch from 4.4 to 4.3 October 13, 2019 21:17
@malarzm
Copy link
Contributor Author

malarzm commented Oct 22, 2019

@nicolas-grekas any chance this could be reviewed and hopefully included in 4.3.6?

@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
@nicolas-grekas nicolas-grekas modified the milestones: 4.4, 4.3 Nov 4, 2019
@malarzm malarzm force-pushed the service-locator-cant-be-decorated-mm branch 3 times, most recently from 37e99cc to c2400d6 Compare December 13, 2019 12:38
@malarzm
Copy link
Contributor Author

malarzm commented Dec 13, 2019

@nicolas-grekas I've tweaked the order so all existing tests are happy, but I'm not sure what the fail on PHP 7.1 is

@malarzm malarzm force-pushed the service-locator-cant-be-decorated-mm branch from c2400d6 to 1edaed2 Compare December 13, 2019 14:23
@nicolas-grekas nicolas-grekas force-pushed the service-locator-cant-be-decorated-mm branch from 1edaed2 to 343282b Compare December 17, 2019 10:22
@nicolas-grekas
Copy link
Member

Thank you @malarzm.

nicolas-grekas added a commit that referenced this pull request Dec 17, 2019
This PR was squashed before being merged into the 4.3 branch.

Discussion
----------

[DI] Service locators can't be decorated

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | n/a
| License       | MIT
| Doc PR        | n/a

This popped up while I was trying to update my work project as we have decorated the `messenger.receiver_locator` service. Not sure if this is a regression in DI or a change in messenger that caused the issue thus I'm not marking this as a BC break.

Exception while trying to compile the container:

```
Invalid definition for service "Symfony\Component\DependencyInjection\Tests\Compiler\DecoratedServiceLocator": an array of references is expected as first argument when the "container.service_locator" tag is set.
```

Expected result: service locator can be decorated.

Commits
-------

343282b [DI] Service locators can't be decorated
@nicolas-grekas nicolas-grekas merged commit 343282b into symfony:4.3 Dec 17, 2019
This was referenced Dec 19, 2019
@malarzm
Copy link
Contributor Author

malarzm commented Dec 31, 2019

@nicolas-grekas apparently this change was not enough for ./bin/console debug:container, I'm facing same error as originally. From the top of your head, is the command working somehow differently?

@nicolas-grekas
Copy link
Member

Yes, the command loads a fake container from an XML dump, so this might trigger some differences. Should be checked.

@malarzm
Copy link
Contributor Author

malarzm commented Dec 31, 2019

@nicolas-grekas the problem is caused by a direct call to ServiceLocatorTagPass introduced in 820da66 (#34755) Unfortunately I have no clue why the change was needed or how to proceed given how we ended up fixing original issue.

nicolas-grekas added a commit that referenced this pull request Jan 6, 2020
…cator on the decorated definition (malarzm)

This PR was merged into the 4.3 branch.

Discussion
----------

[DI] DecoratorServicePass should keep container.service_locator on the decorated definition

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #33670 (comment)
| License       | MIT
| Doc PR        | -

`container.service_locator` is special because it tells how the arguments of the constructor should be interpreted.

/cc @malarzm

Commits
-------

99dab87 [DI] DecoratorServicePass should keep container.service_locator on the decorated definition
@fabpot fabpot mentioned this pull request Jan 21, 2020
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