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

Skip to content

[DependencyInjection] Use ID of the original service when key not specified in service_locator config #48653

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

upyx
Copy link
Contributor

@upyx upyx commented Dec 14, 2022

Q A
Branch? 7.0
Bug fix? no (but discussable #48454 (comment))
New feature? yes
Deprecations? yes (in #48686)
Tickets Implements #48454
License MIT
Doc PR symfony/symfony-docs#...

It fixes bug/implementes feature described in #48454

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "6.3" but it seems your PR description refers to branch "5.4".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1;
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition2;

require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
Copy link
Contributor

@Bilge Bilge Dec 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I was also in the middle of trying to figure this out, I know why you did this, but probably most people reading this PR will not. I explained the issue here and @chalasr has taken a different approach to avoid referencing the unloaded class.

However, I think we need to take further action with respect to this bug, because this is indicative that we have tests with hidden dependencies and this particular bug has existed for almost 1.5 years undetected. Relying on the happenstance deterministic (alphabetical) ordering of tests is bad because it means tests cannot be run in isolation, which makes development harder. The best way I know to remedy this is to apply executionOrder="random" to the phpunit.xml config, which should be done for all such files in this repository.

Copy link
Contributor

@Bilge Bilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document the new method.

@@ -101,6 +92,31 @@ protected function processValue($value, bool $isRoot = false)
return new Reference($id);
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my view, this needs documentation to explain what it is doing and why. The method name certainly gives no indication as to what is going on here.

Suggested change
/**
/**
* Replaces numeric service IDs with service names.

The method name could probably be improved along these lines, also, e.g. replaceNumericServiceLocatorKeys.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion!

Comment on lines 108 to 115
} elseif (\is_int($k)) {
$i = null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

$services[$k] = $v;
}

ksort($services);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I knew... I extracted this code for reusing. The ksort() was removed from the register method on c67c2df. I have no idea why it still exists in processValue.

@Bilge
Copy link
Contributor

Bilge commented Dec 14, 2022

By the way, there is no YAML fixture that actually tests the !service_locator tag works at all. We might consider adding a test case to YamlFileLoaderTest for this.

@chalasr
Copy link
Member

chalasr commented Dec 14, 2022

Please target 6.3. As discussed in #48454 this does not qualify as a bugfix but a feature as it is changing a behavior introduced 4 years ago that some people might rely on and some others probably worked around it by specifying keys explicitly.

By the way, there is no YAML fixture that actually tests the !service_locator tag works at all. We might consider adding a test case to YamlFileLoaderTest for this.

Agreed. PR welcome to add that missing test case (on the lowest maintained branch where it's applicable, probably 5.4).

@upyx upyx force-pushed the ids-in-service-locator branch from afb0b40 to 064bee1 Compare December 14, 2022 20:40
@upyx upyx changed the base branch from 5.4 to 6.3 December 14, 2022 20:41
@upyx upyx changed the title Fix IDs in ServiceLocator Use ID of the original service when key not specified in service_locator config Dec 14, 2022
@carsonbot carsonbot changed the title Use ID of the original service when key not specified in service_locator config [DependencyInjection] Use ID of the original service when key not specified in service_locator config Dec 15, 2022
@chalasr
Copy link
Member

chalasr commented Dec 20, 2022

Closing as the 7.0 branch does not exist yet. See #48686

@chalasr chalasr closed this Dec 20, 2022
@Bilge
Copy link
Contributor

Bilge commented Dec 20, 2022

Dude... what. Even @nicolas-grekas OK'd the 6.x release implicitly in #48454 by stating it's a new feature, which according to the docs, means the target branch is 6.x.

image

@chalasr
Copy link
Member

chalasr commented Dec 20, 2022

#48686 implements that feature on 6.x.

@upyx
Copy link
Contributor Author

upyx commented Dec 20, 2022

@Bilge so do we not need to deprecate anything?

@chalasr if it so, it is the right PR, but not #48686

@upyx
Copy link
Contributor Author

upyx commented Dec 20, 2022

@chalasr @nicolas-grekas
Please, could you get clear, should we deprecate the current undefined/unexpected/wrong documented but implemented behavior or not?

#48454 (comment)
#48454 (comment)

@wouterj
Copy link
Member

wouterj commented Dec 20, 2022

This is a feature, but we have to take care of compatibility as to not break applications currently relying on the "odd behavior". Stability of behavior and code is the number 1 priority for anything in Symfony.

In this case, it is a bit tricky on how to change the behavior in a smooth way (we can't change behavior in 7.0 without a deprecation in 6.x, but we also can't have deprecations in 6.x that can't be fixed). Fortunately, 6.3 is nearly 6 months away still (and 7.0 almost a year from now), so we have all the time to figure out the best path forwards.

In any case, #48686 looks like a more promising PR than this one for 6.x (giving it doesn't change behavior). Let's continue finding the best solution in that PR.

nicolas-grekas added a commit that referenced this pull request Dec 22, 2022
…ce_locator" config (upyx)

This PR was merged into the 6.3 branch.

Discussion
----------

[DependencyInjection] Deprecate integer keys in "service_locator" config

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | no
| Deprecations? | yes
| Tickets       | Deprecation befor #48653
| License       | MIT
| Doc PR        | symfony/symfony-docs#17576

It deprecates undefined/wrong behaviour of https://symfony.com/doc/current/service_container/service_subscribers_locators.html#defining-a-service-locator

Commits
-------

57c2365 [DependencyInjection] Deprecate integers keys in "service_locator" config
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Feb 21, 2023
…pyx)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[DependencyInjection] Remove not implemented behavior

Currently numeric keys are used, but it will be deprecated and changed in 7.0.

Deprecation: symfony/symfony#48686
New behavior: symfony/symfony#48653

Commits
-------

a8770de [DependencyInjection] Remove not implemented behavior
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.

6 participants