Skip to content
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

Autoconfigure in default configuration isn't possible when we have an inheritance of services #24183

Closed
FabienSalles opened this issue Sep 13, 2017 · 4 comments

Comments

Projects
None yet
6 participants
@FabienSalles
Copy link

commented Sep 13, 2017

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

I didn't find any issue for this so I create this one. After I converted all my services with the autowiring feature I tried to use autoconfigure by default and I blocked when I had a service that inherite an other one.

Initially I had this :

<services>
        <defaults autowire="true" />

        <service id="parent_form_type"
             class="AppBundle\Form\MyParentFormType">
            <argument key="$parameter">%my_parameter%</argument>
       </service>

        <service id="child_form_type"
            class="AppBundle\Form\MyChildFormType"
            parent="parent_form_type"
            autowire="true">
            <tag name="form.type" />
        </service>
</services>

I removed the abstract attribute in my parent service in order to avoid this issue and I had to add the autowire="true" in my child service to avoid this one :

[Symfony\Component\Config\Exception\FileLoaderLoadException]                
  Attribute "autowire" on service "child_form_type" cannot be inherited from "defaults" when a "parent" is set. Move your child definitions to a separate file or define this attribute explicitly in app/config/services/form.xml (which is being imported from "app/config/services").

So I changed my default tag :

<defaults autowire="true" autoconfigure="true"/>

And I had this error (same that before for autowiring) :

[Symfony\Component\Config\Exception\FileLoaderLoadException]                                                    
  Attribute "autoconfigure" on service "child_form_type" cannot be inherited from "defaults" when a "parent" is set. Move your child definitions to a separate file or define this attribute explicitly in app/config/services/form.xml (which is being imported from "app/config/services"). 

So I did the same thing for autowiring and set it directly in my child service :

<service id="child_form_type"
    class="AppBundle\Form\MyChildFormType"
    parent="parent_form_type"
    autowire="true"
    autoconfigure="true">
</service>

And I had this error :

[Symfony\Component\Config\Exception\FileLoaderLoadException]                                                     
  The service "child_form_type" cannot have a "parent" and also have "autoconfigure". Try setting autoconfigure="false" for the service in app/config/services/form.xml (which is being imported from "app/config/services").

I tried to set autoconfigure to false like the error said but I got the initial error again :

<service id="child_form_type"
    class="AppBundle\Form\MyChildFormType"
    parent="parent_form_type"
    autowire="true"
    autoconfigure="false">
</service>
[Symfony\Component\Config\Exception\FileLoaderLoadException]                                                    
  Attribute "autoconfigure" on service "child_form_type" cannot be inherited from "defaults" when a "parent" is set. Move your child definitions to a separate file or define this attribute explicitly in app/config/services/form.xml (which is being imported from "app/config/services"). 

I think, this inheritance problem shouldn't occurs when we directly set the option in the service.

@xabbuh

This comment has been minimized.

Copy link
Member

commented Nov 13, 2017

@nicolas-grekas Can you have a look here?

@stof

This comment has been minimized.

Copy link
Member

commented Nov 13, 2017

The last error indeed looks wrong.

@nicolas-grekas

This comment has been minimized.

Copy link
Member

commented Nov 24, 2017

I just tried reproducing the last error using your examples, but I didn't manage to make it fail.
Can you please provide a reproducer that I could run locally?

@FabienSalles

This comment has been minimized.

Copy link
Author

commented Nov 25, 2017

I also tried to reproduce it again with the symfony-standard repository and after with my old project but it works fine now. May be it was a caching issue.

Sorry for the noise and for taking your time. I close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.