Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DI] Prevent AutowirePass from triggering irrelevant deprecations#22282

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:2.8fromchalasr:autowiring-deprecated-defs
Apr 5, 2017

Conversation

@chalasr
Copy link
Member

@chalasrchalasr commentedApr 4, 2017
edited
Loading

QA
Branch?2.8
Bug fix?no (just a failing test case atm)
New feature?no
BC breaks?no
Deprecations?no
Tests pass?no
Fixed ticketsn/a
LicenseMIT
Doc PRn/a

For populating available types the AutowirePass iterates over$container->getDefinitions() trying to instantiate a reflection class for each definition.
Problem is that if one of these classes is deprecated, a notice is triggered due to the reflection, even if the service is actually never used.

Right now this only reproduces the issue with a failing test case, this bug (if we agree it's a bug) breaks the test suite of a bundle I maintain (seehttps://travis-ci.org/lexik/LexikJWTAuthenticationBundle/jobs/218275650#L262)

Solutions I can think about for now:

  • Skip deprecated definitions from type registering, meaning that if a service is deprecated a day, all autowired services that rely on it will suddenly be broken, also the bug would remain if the definition is not deprecated but relies on a deprecated class, not good I think
  • Register an error handler ignoring deprecations during the type registering process (AutowirePass#populateAvailableType()),works but makes my test suite sayTHE ERROR HANDLER HAS CHANGED. I'll push my try as a 2nd commit.

Thoughts?

@nicolas-grekas
Copy link
Member

We could register an error handler, but I'd do this only for deprecated definitions.

THE ERROR HANDLER HAS CHANGED

restoring the previous error handler properly should fix that issue.

@nicolas-grekasnicolas-grekas added this to the2.8 milestoneApr 5, 2017
@chalasrchalasrforce-pushed theautowiring-deprecated-defs branch 4 times, most recently from333fd36 to0dbb1ebCompareApril 5, 2017 12:06
@chalasrchalasr changed the title[DI] AutowirePass triggers irrelevant deprecation notices[DI] Prevent AutowirePass from triggering irrelevant deprecationsApr 5, 2017
}

if ($deprecated) {
restore_error_handler();

Choose a reason for hiding this comment

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

this needs to happen even when the previous code throws (eg the previous error handler)

}

if ($deprecated =$definition->isDeprecated()) {
$prevErrorHandler =set_error_handler(function ($level,$message,$file,$line,$context)use (&$prevErrorHandler) {
Copy link
Member

@nicolas-grekasnicolas-grekasApr 5, 2017
edited
Loading

Choose a reason for hiding this comment

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

$context is deprecated in 7.2, let's not use it

returnfalse;
}

return$prevErrorHandler ?$prevErrorHandler($level,$message,$file,$line,$context) :false;

Choose a reason for hiding this comment

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

onliner:
return E_USER_DEPRECATED === $level || !$prevErrorHandler ? false : $prevErrorHandler($level, $message, $file, $line);

@chalasr
Copy link
MemberAuthor

chalasr commentedApr 5, 2017
edited
Loading

Comments addressed, thanks!
/cc@xabbuh this is heavily inspired from#22274,@nicolas-grekas's comments should be good for it as well (#22282 (comment)).

@chalasrchalasrforce-pushed theautowiring-deprecated-defs branch 2 times, most recently from069e2ff to6f5b183CompareApril 5, 2017 13:50

if ($deprecated =$definition->isDeprecated()) {
$prevErrorHandler =set_error_handler(function ($level,$message,$file,$line)use (&$prevErrorHandler) {
returnE_USER_DEPRECATED ===$level || !$prevErrorHandler ?false :$prevErrorHandler($level,$message,$file,$line);
Copy link
Member

Choose a reason for hiding this comment

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

I don't find this very readable. Can we at least add some parentheses?

Copy link
MemberAuthor

@chalasrchalasrApr 5, 2017
edited
Loading

Choose a reason for hiding this comment

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

parentheses added

@chalasrchalasrforce-pushed theautowiring-deprecated-defs branch from6f5b183 to77927f4CompareApril 5, 2017 14:41
@fabpot
Copy link
Member

Thank you@chalasr.

@fabpotfabpot merged commit77927f4 intosymfony:2.8Apr 5, 2017
fabpot added a commit that referenced this pull requestApr 5, 2017
…cations (chalasr)This PR was merged into the 2.8 branch.Discussion----------[DI] Prevent AutowirePass from triggering irrelevant deprecations| Q             | A| ------------- | ---| Branch?       | 2.8| Bug fix?      | no (just a failing test case atm)| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | no| Fixed tickets | n/a| License       | MIT| Doc PR        | n/aFor populating available types the AutowirePass iterates over `$container->getDefinitions()` trying to instantiate a reflection class for each definition.Problem is that if one of these classes is deprecated, a notice is triggered due to the reflection, even if the service is actually never used.~~Right now this only reproduces the issue with a failing test case~~, this bug (if we agree it's a bug) breaks the test suite of a bundle I maintain (seehttps://travis-ci.org/lexik/LexikJWTAuthenticationBundle/jobs/218275650#L262)Solutions I can think about for now:- ~~Skip deprecated definitions from type registering, meaning that if a service is deprecated a day, all autowired services that rely on it will suddenly be broken, also the bug would remain if the definition is not deprecated but relies on a deprecated class, not good I think~~- Register an error handler ignoring deprecations during the type registering process (`AutowirePass#populateAvailableType()`), ~~works but makes my test suite say `THE ERROR HANDLER HAS CHANGED`. I'll push my try as a 2nd commit.~~Thoughts?Commits-------77927f4 [DI] Prevent AutowirePass from triggering irrelevant deprecations
@chalasrchalasr deleted the autowiring-deprecated-defs branchApril 5, 2017 16:49
fabpot added a commit that referenced this pull requestApr 5, 2017
…g reflection against all existing services (nicolas-grekas)This PR was merged into the 3.3-dev branch.Discussion----------[BC BREAK][DI] Always autowire "by id" instead of using reflection against all existing services| Q             | A| ------------- | ---| Branch?       | 3.3| Bug fix?      | no| New feature?  | yes| BC breaks?    | yes - compile time only| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -(patch best reviewed [ignoring whitespaces](https://github.com/symfony/symfony/pull/22295/files?w=1).)"By-id" autowiring, as introduced in#22060 is free from all the issues that "by-type" autowiring has:- it has no magic and requires explicit type<>id matching (*vs* using reflection on all services to cherry-pick *the* one that matches some type-hint *at that time*, which is fragile)- it is free from any ambiguities (*vs* the Damocles' sword of breaking config just by enabling some unrelated bundle)- it is easily introspected: just look at DI config files (*vs* inspecting the type-hierarchy of all services + their type-hints)- ~~it is side-effect free, thus plain predictable (*vs* auto-registration of discovered types as services)~~- it plays nice with deprecated services or classes (see#22282)- *etc.*Another consideration is that any "by-type" autowired configuration is either broken (because of future ambiguities) - or equivalent to a "by-id" configuration (because resolving ambiguities *means* adding explicit type<>id mappings.) For theoreticians, we could say that "by-id" autowiring is the asymptotic limit of "by-type" autowiring :-)For all these reasons - and also because it reduces the complexity of the code base - I propose to change the behavior and only support "by-id" autowiring in 3.3. This will break some configurations relying on "by-type" autowiring. Yet the break will only happen at compile-time, which means this won't *silently* break any apps. For all core Symfony services, they will work out of the box thanks to#22098 *et al.* For the remaining services, fixing ones config should be pretty straightforward: just follow the suggestions provided by the exception messages. If they are fine to you, you'll end up with the exact same config in the end. And maybe you'll spot issues that were hidden previously.Commits-------cc5e582 [BC BREAK][DI] Always autowire "by id" instead of using reflection against all existing services
This was referencedMay 1, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@xabbuhxabbuhxabbuh left review comments

Assignees

No one assigned

Projects

None yet

Milestone

2.8

Development

Successfully merging this pull request may close these issues.

5 participants

@chalasr@nicolas-grekas@fabpot@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp