Closed (fixed)
Project:
Drupal core
Version:
10.0.x-dev
Component:
base system
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
7 Feb 2022 at 15:56 UTC
Updated:
25 Feb 2022 at 11:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
catchSince this prevents some patches being committed, bumping to critical.
Comment #3
mondrakeI suppose we could add that to the baseline short term, while we file and wait an issue upstream to prevent this being reported?
Comment #4
mallezieAm i misreading something, but that MR should be comitted to D9.4 which does not have PHPStan?
Comment #5
mallezieIf reading summary correct here the point is to add deprecated code (in a test here?). This should be marked explicitly as phpstan-ignore then (or added to the baseline).
Comment #6
mondrakeI think @catch was prepping the D10 commit that needs to go first anyway in Drupal’s workflow
Comment #7
mallezieI see. But then indeed PHPStan is 'correct' here. PHPStan expects when you deprecate code, you also remove usages of it. (Since using deprecated code is a level 0 notice). So in this case we add the exception by saying on that line, ignore it, or add it to the baseline (if the plan is to later remove, which is the case here, so i would say indeed add it to the baseline)
Comment #8
mondrakeActually if the deprecation is for D10, the D10 patch should just not have the legacy test, no?
Comment #9
mondrake#8, see #3217699-25: Convert select query extenders to backend-overrideable services
Comment #10
catchWe add deprecation tests for most new Drupal core deprecations, I don't think we want to be adding every single one to the phpstan baseline.
Comment #11
mallezie@catch this is not needed. Only here we're taking a bit of a 'shortcut' were we add a 'deprecated in D10' item in D10. (Which we do to be able to cherry-pick it to D9, but actually in D10 it should not be there, since it's deprecated in D10).
Normal flow would be we add a 'deprecated in D11', with deprecation test to D10 branch, which PHPStan will not flag untill we open the D11 branch, then phpstan will flag it to have it removed in D11 (which is correct).
In this specific case we have 2 options, add the usage of a deprecated function in D10 (and add it to the baseline to remove later), or only add it to D9.
Comment #12
catch@mallezie we have a lot of code that is deprecated for removal in 10.0.0 in the 10.0.x branch, because we're still in the process of removing all of that deprecated code. This isn't only an issue for new changes if we run phpstan on the whole code base per #3259355: Always do a full phpstan analysis on DrupalCI.
Comment #13
mallezieIn our current setup we only have deprecation rules which are included in the mglaman/phpstan-drupal package.
https://github.com/mglaman/phpstan-drupal/tree/main/src/Rules/Deprecations
Specific rule in the above context kicking in is StaticServiceDeprecatedServiceRule.php
Question is how we want phpstan to notice our deprecations. If we want all deprecations to be flagged (this might include deprecations for D11, which we might not want (yet)) we should add the https://github.com/phpstan/phpstan-deprecation-rules package.
To filter between what deprecations to flag (the ones for D10, but not the ones for D11) we should check how upgrade_status does this (if that does it)
If we don't want deprecations to be flagged we should disable the rules included in the phpstan-drupal package.
Comment #14
catchThe main issue here is that we don't want deprecations flagged in phpunit tests marked @legacy. We know they're going to call deprecated code because that's the point of them. There are already multiple steps to deprecating code (deprecation itself, change record, test coverage, release note, then removing the deprecation and test in the next version, and possibly rector rules if we add those), and that is enough steps really. So if we could add support for @legacy, that would be good.
In general, I think it's OK (probably good) for other core code to be flagged if it's using something deprecated, because this will either be a failed Drupal deprecation, or something upstream from Symfony. However, disabling all deprecation checking, then enabling it again when we don't need to implement workarounds for the current core workflow would be fine I think.
Comment #16
mallezieThis MR disables the (partial) deprecation checking we have at the moment.
I've created #3263109: Use PHPStan for deprecation checking to further discuss how to handle deprecations with phpstan.
Comment #17
mallezieComment #18
alexpottThis looks great to me. We3 already have deprecated service testing via Symfony's PHPUnit bridge so this is duplicating and the only things it is discovering is correct usage in legacy tests.
Comment #19
alexpottI've had another think about this and I think we can just add a comment to the legacy test to disable the phpstan check for the next line. It means we'll still benefit from untested code that calls a deprecated service being found and it's not that much an onus to do.
Here's a new patch that does just this.
Comment #20
catch#19 looks fine.
I'm not convinced it's going to work if we want to enable phpstan's own deprecation checking to cover everything, would be hundreds of these, but we can revisit it when we're closer to doing that.
Comment #21
mondrake#19 is to me the best option ATM; may require some extra work to PHPStan-ignore calls in legacy tests when deprecating something but I think that's OK, PHPStan will tell you what.
Comment #22
alexpottAdding credit for @catch and @mondrake
Comment #23
taran2lgreat! happy to see that direction with comments has been taken
Comment #24
mglaman<3 I love it! It also makes it easy to grep for and find usages of ignores later on. Thanks @alexpott!
Comment #25
mallezieLooks good to me. For sure since we already now with the legacy tag, that those tests need to go in the next version.
Comment #26
mondrakeSee upstream https://github.com/phpstan/phpstan/issues/4452
Comment #27
catchNeeds a re-roll.
Comment #28
alexpottcore/modules/node/tests/src/Functional/NodeRevisionPermissionsTest.php had been deleted so easy to reroll.
Comment #30
catchCommitted 30e53df and pushed to 10.0.x. Thanks!