Problem/Motivation

when running a scan on php 8.1 deprecation warnings can get triggered during a scan breaking the ajax/json response.

ResponseText: Deprecated: Return type of GuzzleHttp\Cookie\CookieJar::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php on line 220
Deprecated: Return type of GuzzleHttp\Cookie\CookieJar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php on line 225
{"status":true,"percentage":"100","message":"Completed 1 of 1.","label":"Analysis complete for pathauto."}

This is actually a core issue with the version of Guzzle pinned to the D9 release #3225966: Consider loosening our constraint to allow sites to install Guzzle 6 or 7, or otherwise handle PHP 8.1 deprecations for Guzzle 6. Documenting it here to connect the pieces for anyone running into it.

Steps to reproduce

Creating a development environment with PHP 8.1 and error_reporting = E_ALL
Install upgrade_status.
Run a upgrade scan on any module.

Proposed resolution

This can probably only be fixed with a core release.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

neclimdul created an issue. See original summary.

neclimdul’s picture

Postponing since this probably can't be fixed in upgrade_status.

neclimdul’s picture

Status: Postponed » Needs review
StatusFileSize
new10.64 KB

couple updates

1) realized to actually _break_ the batch you need to be using devel and have it disable the error handling. This is the suggested setting for development environments so not too weird still. With the drupal error handler you seem to get a bunch of big red deprecation session messages which is still not great.

2) upgrade status _could_ bypass the code in guzzle triggering the exception by providing its own CookieJar. Turns out its pretty straight forward and seems to work. Patch attached.

akshaydalvi212’s picture

Assigned: Unassigned » akshaydalvi212

Hello @neclimdul,

Thanks for the patch,
I will review the patch

akshaydalvi212’s picture

Assigned: akshaydalvi212 » Unassigned
Issue summary: View changes
Status: Needs review » Needs work
StatusFileSize
new194.46 KB

Hello @neclimdul,

After installing and/or enabling the module using composer command:
composer require 'drupal/upgrade_status:^3.14'.

Using patch #3, it gets applied easily but while scan process it encountered following error:

hence shifting the issue status to needs work.

Thanks and regards.

jaykumar95’s picture

hey @akshaydalvi212, can you please check the src/CookieJar.php file is created inside this module's folder or not (for mine it's created on root folder).
can you please show commands you run to apply this patch #3?

neclimdul’s picture

Status: Needs work » Needs review

Sounds like the failure might have been a problem applying the patch? I'm using this in our upgrade process without the failure.

That said, I need to confirm if this is still needed after the core fix was applied. Maybe still useful if people are using the suggested or which ever project that maintained the tighter requirements.

gábor hojtsy’s picture

Title: Deprecation warnings running scan on PHP 8.1 » Deprecated function: Return type of GuzzleHttp\Cookie\CookieJar when running Upgrade Status on PHP 8.1
gábor hojtsy’s picture

There were also existing fails on PHP 7.4 and 8.0 which I just fixed in #3302828: Upgrade Status tests fail on PHP 7.4 and PHP 8.0 due to lack of rules.neon used from phpstan-drupal, so let's run this on all the environments.

gábor hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

In #3302828: Upgrade Status tests fail on PHP 7.4 and PHP 8.0 due to lack of rules.neon used from phpstan-drupal the PHP 8.1 environment was still failing with this error. Providing our own CookieJar sounds like a reasonable stopgap, so let's do this!

  • f834f7c committed on 8.x-3.x
    Issue #3274645 by neclimdul, Gábor Hojtsy, Jaykumar95: Deprecated...
gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed
lobodakyrylo’s picture

Now I get another error:

PHP message: PHP Fatal error: Declaration of Drupal\upgrade_status\CookieJar::withCookieHeader(Psr\Http\Message\RequestInterface $request) must be compatible with GuzzleHttp\Cookie\CookieJarInterface::withCookieHeader(Psr\Http\Message\RequestInterface $request): Psr\Http\Message\RequestInterface in /upgrade_status/src/CookieJar.php on line 28

jaykumar95’s picture

Status: Fixed » Needs work
jaykumar95’s picture

As stated in above patch #3 inside Drupal\upgrade_status\CookieJar.php file if the core have guzzlehttp/guzzle version 7, then no need for CookieJar.php in module itself.

neclimdul’s picture

"Can be removed after Core allows Guzzle 7" hmm yeah... it does already? I have questions for me 5 months ago. I'll take a look and see if I can smooth this out.

fgm’s picture

As mentioned by lobodacyril, that has now become more severe, actually breaking with today's upgrade_status HEAD, Drupal current stable 9.4.6 and PHP 8.1.10.

Same issue with Drupal 9.5.0-beta1 so not minor, but actually major since it is broken on both a stable version and the upcoming new stable.

Fatal error: Declaration of Drupal\upgrade_status\CookieJar::withCookieHeader(Psr\Http\Message\RequestInterface $request) must be compatible with GuzzleHttp\Cookie\CookieJarInterface::withCookieHeader(Psr\Http\Message\RequestInterface $request): Psr\Http\Message\RequestInterface in /Users/fgm/src/Drupal/d9/drop9/web/modules/contrib/upgrade_status/src/CookieJar.php on line 284

fgm’s picture

Priority: Minor » Major
gábor hojtsy’s picture

So what do we do then, should we remove our override and depend on which Guzzle the setup takes?

neclimdul’s picture

Status: Needs work » Needs review
StatusFileSize
new493 bytes

I've really wanted to get to this sooner I promise. This is kind of annoying because drupal-recommends still requires guzzle 7. So I guess the "remove later" still makes sense.

Looking at this closer, because of the way types work we can actually just make the signature more specific then the Guzzle 6 interface to match the Guzzle 7 interface and everything should work.

This worked for me but would be could for someone else to verify I didn't miss something.

jungle’s picture

StatusFileSize
new1.9 KB

Patch in #20 is not enough for Drupal core 9.5.0-beta2.

jungle’s picture

StatusFileSize
new1.9 KB
+++ b/src/CookieJar.php
@@ -239,7 +239,7 @@ class CookieJar implements CookieJarInterface
-    ) {
+    ) :void {

Updated a little bit here

< + ) :void {
---
> + ): void {

rajab natshah’s picture

Facing the same issue
Switched to test and work with:

  "require-dev": {
    "drupal/upgrade_status": "3.x-dev",
    "drupal/core-dev": "~9.0",
    "drush/drush": "~11.0",
    "mglaman/drupal-check": "~1.0",
    "phpspec/prophecy-phpunit": "~2.0"
  },

Patch in #22 is needed to work in PHP 8.0 and PHP 8.1

    "patches": {
      "drupal/upgrade_status": {
        "Issue #3274645: Deprecated function: Return type of GuzzleHttp Cookie CookieJar when running Upgrade Status on PHP 8.1":
        "https://www.drupal.org/files/issues/2022-10-07/3274645-22.patch"
      }
    }
rajab natshah’s picture

Status: Needs review » Reviewed & tested by the community

It feels that this issue fix might be better in a new issue.

claudiu.cristea’s picture

Any news here? This is a blocker for using the module with PHP 8.1

claudiu.cristea’s picture

Issue tags: +PHP 8.1
vladimiraus’s picture

claudiu.cristea’s picture

I'm already on PHP 8.1, so Guzzle 7

  • 6282f59 committed on 8.x-3.x
    Issue #3274645 followup by neclimdul, jungle: Fix PHP 8.1 compatibility...
gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Sorry for the delay, committed. Will make a release shortly unless there are other pressing things too.

gábor hojtsy’s picture

https://www.drupal.org/project/upgrade_status/releases/8.x-3.18 out now, enjoy! Also please use new issues for followups for better tracking. Thanks a lot!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.