Problem/Motivation
When the Statement classes were developed, they were meant to be extensions of the base PDOStatement class.
As we moved on, Statement classes are now largely decoupled from PDO, but for fetch mode we still support all the PDO-provided modes, even though some of them are not really used - just to keep compatibility with PDO. Non-PDO drivers (and the prefetching statement) are therefore forced to develop and maintain compatibility layers to mimick PDO behavior, for no purpose.
FTR, doctrine/dbal has reduced the supported fetch modes, and dropped using \PDO::FETCH_* constants in favour of an abstract implementation.
Candidate modes for deprecation:
- \PDO::FETCH_BOTH
\PDO::FETCH_CLASS- \PDO::FETCH_CLASS | \PDO::FETCH_CLASSTYPE
\PDO::FETCH_COLUMN- \PDO::FETCH_LAZY
- \PDO::FETCH_INTO
Proposed resolution
Only allow these fetch modes:
- \PDO::FETCH_ASSOC,
- \PDO::FETCH_CLASS,
- \PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE,
- \PDO::FETCH_COLUMN,
- \PDO::FETCH_NUM,
- \PDO::FETCH_OBJ,
Deprecate unused fetch modes for removal in a future major.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3345938
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:
- 3345938-deprecate-support-for
changes, plain diff MR !4468
Comments
Comment #2
mondrakeLet's see this - curious to know how much it fails.
Comment #3
daffie commentedMy big worry with this change is that it will break (in Drupal 11) existing sites. I know that is allowed. Only we must be very sure that everything that we should allow is not deprecated in this issue.
Can we add a comment with were we could the values from. For better maintainability and documentation.
Why are only those 4 settings allowed. Could you explain for all 3 methods were they are added.
The testbot is failing with over 300 fails.
Comment #4
mondrake#3
Any deprecation+removal causes that, though.
3.1 - it's from PHP source code, https://github.com/php/php-src/blob/master/ext/pdo/php_pdo_driver.h#L65-L80. Let's not take this as a reviewable patch - was just here to see 'what' fails. Afterwards, all this will have to get a different shape.
3.2 - simply, I took the fetch modes that I think are really used in practice, and used the patch to check which others are. It turns out only FETCH_CLASS is used outside of those 4 in runtime code (not tests). And even that is used in one place only. If #3275858-41: View's ResultRow uses deprecated dynamic properties goes in, the failures will be very few and only related to tests.
NOTE: there are fetch modes like FETCH_FUNC, FETCH_NAMED and FETCH_KEY_PAIR that we are currently only (theoretically) supporting if using StatementWrapper on a PDO connection. These were introduced in PHP after StatementPrefetch was developed, and currently that class would fail if those modes were requested, since it was not adjusted accordingly.
So here I'd like first of all to discuss/agree which fetch modes we should really support, why they would be needed, ensure testing, and finally get rid of the not necessary ones.
Comment #5
alexpottThis issue also needs to look at what is used in contrib - starting with core is fine but we need to search contrib for all the modes we decide to not support.
Comment #8
mondrakeChanged to MR workflow, and made use of the new FetchTrait.
Comment #9
mondrakeComment #10
mondrakeComment #11
smustgrave commentedCould a CR be written for this?
Change looks good and assuming since nothing broke (test wise) that additional tests aren't needed?
Comment #12
mondrakeAdded draft CR https://www.drupal.org/node/3377999
Comment #13
smustgrave commentedCR LGTM
Comment #14
daffie commentedComment #15
mondrakeComment #16
daffie commentedAll code changes look good to me.
The IS and the CR are in order.
For me it is RTBC.
Comment #17
longwaveRe #4/#5 there doesn't seem to be any discussion of which modes we should actually support, nor any evidence that the deprecated modes are not used in contrib. It would at least be good to know we aren't entirely disrupting something widely used in contrib, if we are dropping these with no replacement.
Comment #18
mondrakeMy intention was to remove also
since it's only used once in core runtime, but trying to remove that stalled at #3275858: View's ResultRow uses deprecated dynamic properties. So I went for keeping them.
I'm leaving checking contrib for the next person; I'm not very familiar on querying across multiple projects. I tried a bit but ended up in zillions of D7 projects + zillion of dupes of the base classes part of distributions.
Comment #19
longwaveI searched contrib and could not find uses of FETCH_DEFAULT, FETCH_LAZY, FETCH_BOUND, FETCH_INTO, FETCH_NAMED, FETCH_FUNC or FETCH_CLASSTYPE.
FETCH_BOTH is used by excel2webpage and w3c_validator.
FETCH_KEY_PAIR is used by gtfs.
I suspect that all these usages could be replaced by a different fetch option and as there are only three I am not particularly worried about this change any longer.
Comment #20
mondrakeThanks @longwave! Would you mind sharing your search steps? It would be really useful.
Usage of \PDO::FETCH_KEY_PAIR is problematic with current HEAD because AFAICS it means the module cannot run on SQLite.
Comment #21
longwaveI use http://grep.xnddx.ru/ which seems to be updated every few weeks, and has been more reliable for me.
GitLab search is also available, which in this case brings up a different contrib module plus some false positives in vendor code: https://git.drupalcode.org/search?scope=blobs&search=FETCH_KEY_PAIR&grou...
Comment #22
mondrakeThanks for #21!
Comment #23
mondrakeNothing has changed and #19 sounds like a signoff then I think I can put this back to RTBC.
Comment #24
catchHaven't reviewed this in enough depth to commit it, but general +1 to reducing the surface area here. I had a quick look at the three usages @longwave found. FETCH_BOTH looks like it's unnecessary and they could switch to more or less any of the standard ones. FETCH_KEY_PAIR would require a bit of refactoring, but reasonable to require that for a major release given it's a single usage.
Comment #25
quietone commentedI'm triaging RTBC issues.
I looked at this late last night and after reading the IS and comments I don't see anything left to do. There may be a follow up for project gtfs per #19.
Leaving at RTBC.
Comment #26
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #27
mondrakeRebased and added
@phpstan-ignore-next-lineto calls of deprecated methods that are left in for BC purposes. Back to RTBC.Comment #29
catchThis looks great.
As discussed above, there are 3-4 contrib modules affected by the deprecations, and they can probably just switch to a different fetch mode and be fine. Worst case we could undeprecate one or two if there's a really good reason to use them.