Skip to content

[DIC] !tagged tag list not showing with --show-arguments in debug:container #31340

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
linaori opened this issue May 1, 2019 · 2 comments
Closed

Comments

@linaori
Copy link
Contributor

linaori commented May 1, 2019

Symfony version(s) affected: 3.4+

Description
When using bin/console debug:container my_service --show-arguments and this service contains an argument as !tagged my_tag, it will not properly show the arguments being passed. The XML will only contain a "tagged" element and doesn't tell you which services will be injected. The command line output will tell you there are 0 elements in the iterator.

How to reproduce

services:
    my_service:
        class: stdClass
        arguments: [!tagged my_tag]

    my_tagged_service_1:
        class: stdClass
        tags: [my_tag]

    my_tagged_service_2:
        class: stdClass
        tags: [my_tag]

To verify the services are actually there:

bin/console debug:container --tag=my_tag

Symfony Container Public Services Tagged with "my_tag" Tag
==========================================================

 --------------------- ------------ 
  Service ID            Class name  
 --------------------- ------------ 
  my_tagged_service_1   stdClass    
  my_tagged_service_2   stdClass    
 --------------------- ------------ 

Missing argument information:

bin/console debug:container my_service --show-arguments 
Information for Service "my_service"
====================================

 ---------------- ------------------------- 
  Option           Value                    
 ---------------- ------------------------- 
  Service ID       my_service               
  Class            stdClass                 
  Tags             -                        
  Public           yes                      
  Synthetic        no                       
  Lazy             no                       
  Shared           yes                      
  Abstract         no                       
  Autowired        yes                      
  Autoconfigured   yes                      
  Arguments        Iterator (0 element(s))  
 ---------------- -------------------------

Possible Solution
I would personally already be satisfied if it properly displayed the actual count, and it would be even better if it could display the list of service_ids it would inject.

Iterator (2 element(s))
# or
Tagged Iterator (2 element(s)) [
    my_tagged_service_1
    my_tagged_service_2
]

This is currently making it a bit troublesome to see if your !tagged works and in a more complex system (autoconfigure), if all the services are picked up correctly.

@jschaedl
Copy link
Contributor

jschaedl commented May 3, 2019

In debug mode the ContainerDebugCommand uses a non compiled container. So services injected in iterable arguments are not resolved and the IteratorArgument::getValues() returns an empty array which is the reason for showing Iterator (0 element(s)).

However if you use ./bin/console debug:container my_service --show-arguments --env=prod the used container will be compiled and the number of Iterator elements are shown correctly:

Information for Service "my_service"
====================================

 ---------------- -------------------------
  Option           Value
 ---------------- -------------------------
  Service ID       my_service
  Class            stdClass
  Tags             -
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        yes
  Autoconfigured   yes
  Arguments        Iterator (2 element(s))
 ---------------- -------------------------

I tried to introduce a compiled container also in debug mode, but got a lot of failing tests. Fixing all the related fixtures and tests feels not like a small bugfix to me and I doubt that something, like this will get merged. So I suggest we remove the number of elements information, when someone executes the command in debug mode.

WDYT?

@linaori
Copy link
Contributor Author

linaori commented May 3, 2019

Would it be an idea to show the name of the tagged iterator instead? That information is available if I recall correctly. If you can see which tag you insert, you can do a --tag=my_tag to see the actual services.


Information for Service "my_service"
====================================

 ---------------- -------------------------------
  Option           Value
 ---------------- -------------------------------
  Service ID       my_service
  Class            stdClass
  Tags             -
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        yes
  Autoconfigured   yes
  Arguments        Tagged Iterator for "my_tag"
 ---------------- -------------------------------

@fabpot fabpot closed this as completed May 6, 2019
fabpot added a commit that referenced this issue May 6, 2019
…and array arguments (jschaedl)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[FrameworkBundle] Show injected services for iterator and array arguments

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      |no
| New feature?  | yes<!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? |no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #31340   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | tbd.

When I have the following service configuration:

```yaml
    App\Word\Checker\StaticWordChecker:
        tags: [app.checker]

    App\Word\Checker\BannedWorldListChecker:
        tags: [app.checker]

    App\Word\WordCheckerTaggedIterator:
        arguments: [!tagged app.checker]

    App\Word\WordCheckerArray:
        arguments:
            - App\Word\Checker\StaticWordChecker: ~
              App\Word\Checker\BannedWorldListChecker: ~
```

and I run:
`./bin/console debug:container App\Word\WordCheckerArray --show-arguments`
```bash
Information for Service "App\Word\WordCheckerArray"
===================================================

 ---------------- -------------------------------------------
  Option           Value
 ---------------- -------------------------------------------
  Service ID       App\Word\WordCheckerArray
  Class            App\Word\WordCheckerArray
  Tags             -
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        yes
  Autoconfigured   yes
  Arguments        Array (2 element(s))
                   - App\Word\Checker\StaticWordChecker
                   - App\Word\Checker\BannedWorldListChecker
 ---------------- -------------------------------------------
```
or

`./bin/console debug:container App\Word\WordCheckerTaggedIterator --show-arguments`
```bash
Information for Service "App\Word\WordCheckerTaggedIterator"
============================================================

 ---------------- -------------------------------------------
  Option           Value
 ---------------- -------------------------------------------
  Service ID       App\Word\WordCheckerTaggedIterator
  Class            App\Word\WordCheckerTaggedIterator
  Tags             -
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        yes
  Autoconfigured   yes
  Arguments        Iterator (2 element(s))
                   - App\Word\Checker\BannedWorldListChecker
                   - App\Word\Checker\StaticWordChecker
 ---------------- -------------------------------------------
```

I can now see the the objects injected into the iterator and array arguments.

Commits
-------

db5fb20 [FrameworkBundle] Show injected services for Iterator and Array
nicolas-grekas added a commit that referenced this issue May 9, 2019
…(jschaedl)

This PR was squashed before being merged into the 3.4 branch (closes #31371).

Discussion
----------

[DI] Removes number of elements information in debug mode

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

With this services config:

```yaml
my_service:
    class: stdClass
    arguments: [!tagged my_tag]

my_tagged_service_1:
    class: stdClass
    tags: [my_tag]

my_tagged_service_2:
    class: stdClass
    tags: [my_tag]
```
Executing `./bin/console debug:container my_service --show-arguments --env=dev` resulted in

```bash
Information for Service "my_service"
====================================

 ---------------- -------------------------
  Option           Value
 ---------------- -------------------------
  Service ID       my_service
  Class            stdClass
  Tags             -
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        yes
  Autoconfigured   yes
  Arguments        Iterator (0 element(s))
 ---------------- -------------------------
```
 With this fix the output changed to:

```bash
Information for Service "my_service"
====================================

 ---------------- ------------
  Option           Value
 ---------------- ------------
  Service ID       my_service
  Class            stdClass
  Tags             -
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        yes
  Autoconfigured   yes
  Arguments        Tagged Iterator for "my_tag"
 ---------------- ------------
```

and with `./bin/console debug:container my_service --show-arguments --env=prod`

```bash
Information for Service "my_service_tagged_iterator"
====================================================

 ---------------- ---------------------------------------------
  Option           Value
 ---------------- ---------------------------------------------
  Service ID       my_service
  Class            stdClass
  Tags             -
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        yes
  Autoconfigured   yes
  Arguments        Tagged Iterator for "my_tag" (2 element(s))
 ---------------- ---------------------------------------------
```

Commits
-------

0da4b83 [DI] Removes number of elements information in debug mode
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

5 participants