Skip to content

[2.3] Return BC compatibility for DI Container #8392

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 1 commit into from

Conversation

stloyd
Copy link
Contributor

@stloyd stloyd commented Jul 1, 2013

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #8347
License MIT

When setting service to null it's considered as existing instead of removed/reset state which is BC break, more in #8347.

When setting service to `null` it's considered as existing instead of removed/reset state.
This PR returns BC compatibility and provides test to ensure that BC is hold.
@lsmith77
Copy link
Contributor

lsmith77 commented Jul 3, 2013

+1

@stof
Copy link
Member

stof commented Jul 3, 2013

@fabpot could this be merged ? The regression in 2.3 for resetManager is quite annoying.

@eduardosoliv
Copy link
Contributor

+1

@eb-jsaraiva
Copy link

I have tested this PR as is and it still doesn't fix the problem being addressed.
There is an array_key_exists check

// re-use shared service instance if it exists
if (array_key_exists($id, $this->services)) {
    return $this->services[$id];
}

which makes the service container return null values. However, changing that to isset() raises another issues, I started to get the following error: You have requested a synthetic service ("request"). The DIC does not know how to construct this service.

@eduardosoliv
Copy link
Contributor

@stloyd @fabpot any news on this?

@richsage
Copy link
Contributor

+1, this unfortunately limits us upgrading from 2.2.x to 2.3.x

@oleg-andreyev
Copy link
Contributor

+1

2 similar comments
@jankramer
Copy link

+1

@eb-jsaraiva
Copy link

+1

@linaori
Copy link
Contributor

linaori commented Jul 25, 2013

This fix will not work completely.

    public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
    {
        $id = strtolower($id);

        // resolve aliases
        if (isset($this->aliases[$id])) {
            $id = $this->aliases[$id];
        }

        // re-use shared service instance if it exists
        if (array_key_exists($id, $this->services)) {
            return $this->services[$id];
        }

You missed this part in your pull request. This array_key_exists has to be changed to isset() as well.

@fabpot
Copy link
Member

fabpot commented Jul 25, 2013

This PR cannot be merged as the change from isset to array_key_exists was done for a reason. So, reverting everything back to isset is not an option. We need to investigate the issue further to find another solution.

@stof
Copy link
Member

stof commented Jul 25, 2013

@fabpot The change from isset to array_key_exists is also what broke the registry in 2.3 (and it was not covered by tests).

If setting the service to null does not allow resetting it anymore, I don't think we can implement the resetting without adding another method. It would mean a second BC rbeak to mitigate the effect of the first one.

@linaori
Copy link
Contributor

linaori commented Jul 25, 2013

random brain spin

May I suggest placeholders to indicate what is supposed to happen with the service key?

    protected function resetService($name)
    {
        $this->container->set($name, new ServiceReset('or how ever you want to call it'));
    }

This could tell the get() to return it but re-initialize the initial service before the actual return happens.

@jankramer
Copy link

@fabpot what was the reason for that particular change? Or do you have a reference as to where this was discussed? Only thing I can seem to find is the commit (ec1e7ca), but that description does not make things much clearer to me.

Anyway, as it seems to me it does not make sense to have entries in the services array with value null. So why not check in the set method if the given value is null, and if so, unsetting the particular entry if it exists? This would fix the BC break AFAIK without having to add another method.

@fabpot
Copy link
Member

fabpot commented Jul 25, 2013

@jankramer isset has been replaced with array_key_exists in PR #7007 which introduces synchronized services.

@fabpot
Copy link
Member

fabpot commented Jul 25, 2013

Can you test PR #8582 which should fix the issue and keep BC?

@fabpot
Copy link
Member

fabpot commented Jul 25, 2013

Symfony tests pass and my local tests tell me that it fixes the issue with Doctrine as well. So, just waiting for some more confirmation from more real-world projects before merging the fix.

@jankramer
Copy link

Yep, just tested and this fixes some issues for me as well.

@fabpot
Copy link
Member

fabpot commented Jul 25, 2013

I've just upgraded one of my projects that had this issue and my patch does fix the problem.

@fabpot
Copy link
Member

fabpot commented Jul 25, 2013

Closing in favor of #8582

@fabpot fabpot closed this Jul 25, 2013
fabpot added a commit that referenced this pull request Jul 25, 2013
This PR was merged into the 2.3 branch.

Discussion
----------

[DependencyInjection] fixed regression where setting a service to null did not trigger a re-creation of the service when getting it (closes #8392)

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8392
| License       | MIT
| Doc PR        | n/a

Commits
-------

50d0727 [DependencyInjection] fixed regression where setting a service to null did not trigger a re-creation of the service when getting it
@stloyd stloyd deleted the bugfix/issue-8347 branch July 25, 2013 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants