Problem/Motivation
With the version bump of mglaman/phpstan-drupal in #3330305: Fix failing "updated deps" test-runs by upping mglaman/phpstan-drupal to latest some Entity Query access check-related errors popped up and were committed to the baseline core/phpstan-baseline.neon.
This issue aims to fix all those errors, which manifest themselves as:
Relying on entity queries to check access by default is deprecated in drupal:9.2.0 and an error will be thrown from drupal:10.0.0. Call \Drupal\Core\Entity\Query\QueryInterface::accessCheck() with TRUE or FALSE to specify whether access should be checked.
💡 See https://www.drupal.org/node/3201242
As it turns out there is still a problem with mglaman/phpstan-drupal relating to accesCheck(), config entities and count queries, see https://github.com/mglaman/phpstan-drupal/issues/530.
Therefore there are still occurrences of the above errors present in the baseline. These should all be about count queries.
Steps to reproduce
Proposed resolution
- There should be no more of the above mentioned errors being suppressed in the baseline.
- TestBot should return green.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3330981
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
spokjeComment #3
spokjeComment #6
spokjeComment #8
spokjeUnsure how to proceed.
There are a number of false positives/negatives, for which I filed upstream issues https://github.com/mglaman/phpstan-drupal/issues/494 and https://github.com/mglaman/phpstan-drupal/issues/496.
Do we want to wait until those are fixed and released, or do we want to get the ones that are solid in now and do the rest later?
Comment #10
smustgrave commentedRemoving credit from myself as I rebase the MR to see if there are failures.
Appears it does have one
Comment #11
spokjeThanks @smustgrave, unsure how this could have passed in previous runs.
Back to NR for #8.
Comment #12
smustgrave commentedDiscussed this one in slack with @Spokje
So the question for the framework managers are do we fix some now and open a postponed follow up for the others later. Or postpone this until the phpstan-drupal fixes are in?
Comment #13
xjmIssue scoping is a release management decision, not a framework decision. So consider this me removing the framework manager tag, adding the release manager tag, and then removing it again because I'm signing off on the change set. :)
The tooling giving false results means we need to review each of these on a case-by-case basis, but since in most cases the access check is executed shortly after being defined, I think it's fine to fix the ones that are definitely wrong first and then the remainder once upstream is fixed. I was able to scan the MR and confirm that there is one
accessCheck()call within a few lines of theexecute()within a few minutes here, so I don't think doing this in two steps creates unnecessary overhead.We should probably file the followup first, though, and explicitly postpone it on the upstream issues.
Comment #14
spokjeThanks @xjm for the explanation in #13.
Putting this one back to NW to work on the follow-up and the split of this issue.
Comment #15
spokjeLet's postpone this on #3336586: Fix failing "updated deps" test-runs by upping mglaman/phpstan-drupal to latest which fixes some false negatives and discovers some new (probably) valid errors.
Comment #16
spokje#3336586: Fix failing "updated deps" test-runs by upping mglaman/phpstan-drupal to latest landed, back to NW.
Comment #17
mallezieComment #18
spokjeThanks @mallezie, must be lack of caffeine...
Comment #19
mallezieFor me the changes look clean and good!Only adding of access checks, and removing them from the baseline.2 things wondering here.
There are still some entity query access checks left (in the baseline). Those might be fixed as well by a new update. Currently on mglaman/phpstan-drupal 1.1.27 (but 1.128 and 1.129 should fix some more?).
https://github.com/mglaman/phpstan-drupal/releases/tag/1.1.28
https://github.com/mglaman/phpstan-drupal/releases/tag/1.1.29
There are still some updated deps failures caused by entity access checks, which might also be fixed if we do the other update first?
See https://www.drupal.org/node/3060/qa and https://www.drupal.org/pift-ci-job/2592021
So not sure if we should do another update first here?
If not this is RTBC for me.Seems i'm crossposting while Spokje still working on it. Ignore my code comments then for now.
Comment #20
spokjePostponing on #3341254: Fix failing "updated deps" test-runs on 10.x.x
Comment #21
mallezieBlocker is in. Let's try this again.
Comment #22
spokjeThe two remaining references in the PHPStan baseline are false negatives and should be solved in
mglaman/phpstan-drupal.Comment #23
smustgrave commentedIf I'm understanding correctly the follow up was #3336586: Fix failing "updated deps" test-runs by upping mglaman/phpstan-drupal to latest
The changes in the MR look good. With no errors after being removed from the baseline think this good.
Comment #24
catchStarted reviewing and 5 out of 5 of the first queries were using accessCheck(TRUE) where it should be FALSE. In practice this never makes a difference for config entity queries since no-one implements query access for them, but we shouldn't set a bad example for contrib.
Anywhere that we're checking for existence or updating should always use accessCheck(FALSE), anywhere that's listing in the UI should use accessCheck(TRUE). If it's ambiguous somewhere, we should pick one and add a comment explaining the choice.
Comment #25
spokjeShould PHPStan(-drupal) be checking for them if that's the case?
Comment #26
catchThe behaviour was only changed for content entity queries, so probably not! https://www.drupal.org/node/3201242
Comment #27
spokjeI was afraid you would say that, but it makes full sense. Back to the drawing board in mglaman/phpsta-drupal, and this is, yet another PHPStan issue that disappears in the mist of time.
Comment #28
spokjeComment #29
mallezieIt might be not that bad as thought.
https://github.com/mglaman/phpstan-drupal/issues/479
The issue is already fixed in phpstan-druoal, just waiting for a new release should be enough.
Comment #30
spokjeI'm sad to say it, but I find myself moving more and more away from anything PHPStan related.
There seems to be always either a policy change, a code style discussion, or a we-need-to-split-this-in-23-sub-issues involved.
Comment #31
spokjeUnblocked.
Comment #34
dpiMinor formatting
Comment #35
spokjeComment #36
spokje(Thanks @dpi)
New approach: Not just slapping an
accessCheck()on all remaining errors, but trying to fix most of them through type-hinting.Comment #37
spokjeComment #38
spokjeComment #39
spokjeComment #40
smustgrave commentedThere's an open thread.
But applying the MR and searching for "^Relying on entity queries to check access by default is deprecated" there are 6 other instances.
Comment #41
spokjeResolved.
.
See IS:
Back to NR.
Comment #42
smustgrave commentedThanks for clarifying. All threads have been resolved. LGTM.
Comment #44
catchI was wrong about the content moderation list builder, it should be TRUE, because it's a list builder so destined for the UI, made a commit to the MR to change it back. The fact we're not getting a deprecation error from that one on tests means that method is likely completely untested (or if not something else is wrong), so tagging for a follow-up.
I also opened #3356516: Deprecate node_get_recent() for the definitely-untested node_get_recent().
Committed/pushed to 10.1.x, thanks!
Comment #46
spokjeOpened #3357071: Ensure ModeratedNodeListBuilder::getEntityRevisionIds has sufficient test coverage