phpfastcache icon indicating copy to clipboard operation
phpfastcache copied to clipboard

saveDocument() - E_DEPRECATED: Couchbase\defaultDecoder(): Passing null to parameter #1 ($bytes) of type string is deprecated

Open MetroConductor opened this issue 1 year ago • 20 comments

What type of issue is this?

Exception/Error/Warning/Notice/Deprecation

Operating system + version

Alpine 3.16

PHP version

8.1.22

Connector/Database version (if applicable)

Couchbase CE 7.2.2 + PECL Extension 3.2.2

Phpfastcache version

9.2.0 ✅

Describe the issue you're facing

Whenever storing a new document (that is, a document that doesn't exist yet), I'm faced with the following exception:

E_DEPRECATED: Couchbase\defaultDecoder(): Passing null to parameter #1 ($bytes) of type string is deprecated

Trace:
  #2 [internal function]: Couchbase\defaultDecoder()
  #3 /var/www/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchbasev3/Driver.php(117): Couchbase\GetResultImpl->content()
  #4 /var/www/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php(137): Phpfastcache\Drivers\Couchbasev3\Driver->driverReadMultiple()
  #5 /var/www/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolTrait.php(402): Phpfastcache\Drivers\Couchbasev3\Driver->getItems()
  #6 /var/www/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php(487): Phpfastcache\Drivers\Couchbasev3\Driver->driverWriteTags()
  #7 /home/cache/src/Cache.php(343): Phpfastcache\Drivers\Couchbasev3\Driver->save()

The interesting thing is, this is only when saving a document that didn't exist previously; updating works without a hitch. I searched high and low, but I couldn't find anyone describing anything similar. Is anyone familiar with this issue?

Suggestion to fix the issue (optional)

It seems like somehow Couchbase's defaultDecoder is called without a payload, which could be because the document indeed doesn't exist yet. If you ask me, there should be a if to prevent the decoder from being called without data

Have you searched in our Wiki before posting ?

  • [X] I have searched over the Wiki

MetroConductor avatar Sep 28 '24 01:09 MetroConductor

Hello curious contributor ! Since it seems to be your first contribution, make sure that you've been:

  • Reading and searching out our WIKI
  • Reading and agreed with our Code Of Conduct
  • Reading and understood our Coding Guideline
  • Reading our README If everything looks unclear to you, tell us what 😄 The Phpfastcache Team

github-actions[bot] avatar Sep 28 '24 01:09 github-actions[bot]

Ok, i'll take a look this weekend

Geolim4 avatar Oct 03 '24 13:10 Geolim4

I'm running into the same issue lately. Have you been able to check this @Geolim4 ?

Thanks for reporting @MetroConductor

Fabbzz avatar Oct 15 '24 19:10 Fabbzz

@Fabbzz @MetroConductor Funny thing is that... I don't know how to fix it ? 😆 My code is following the stubs:

The faulty line:

#3 /var/www/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchbasev3/Driver.php(117): Couchbase\GetResultImpl->content()

https://github.com/PHPSocialNetwork/phpfastcache/blob/8cadd6fe80e1375b77d3a9a11702cb9c96776f55/lib/Phpfastcache/Drivers/Couchbasev3/Driver.php#L117

Seems not to need a parameter as per the official stubs:

https://github.com/JetBrains/phpstorm-stubs/blob/345cde8b2bdc981a07030c18fe7236153c824a05/couchbase/couchbase.php#L260

May @srjlewis do you have an idea on this ? (It's about the Couchbase v3)

Geolim4 avatar Oct 15 '24 19:10 Geolim4

@Geolim4 OK, good because I think we can't... or PHPfastcache needs to retry as I do myself before I totally let my script die so I actually never run into this issue.

I made the following issue @couchbase-php-client : https://github.com/couchbase/couchbase-php-client/issues/185

Let's hope they respond faster then we can try/catch/cache ;)

Fabbzz avatar Oct 15 '24 19:10 Fabbzz

I'm afraid that the issue will leads to nothing as the v3 extension is deprecated and replaced by the v4 since 2 years now :(

Geolim4 avatar Oct 15 '24 20:10 Geolim4

@Geolim4 mhh, that means a huge refactor from your side ?

Fabbzz avatar Oct 15 '24 20:10 Fabbzz

No, the Couchbasev4 support already exists as an extension :) https://github.com/PHPSocialNetwork/couchbasev4-extension

Geolim4 avatar Oct 15 '24 20:10 Geolim4

@Geolim4 Let me dive into that, thanks! Maybe add a deprecated warning for V3 then ?

Fabbzz avatar Oct 15 '24 20:10 Fabbzz

Hi

It looks like it is link to either the following RFC's https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg https://wiki.php.net/rfc/deprecate-implicitly-nullable-types

~~I would like to know which version of PHP and OS these deprication it is showing on.~~ I should read better

@Fabbzz You have created your issue aginst SDK v4 which was completely rewritten. https://github.com/couchbase/php-couchbase is the v3 codebase, and v3 of the SDK is EOL, so couchbase wont fix.

this is the defaultDecoder methordd within v3 https://github.com/couchbase/php-couchbase/blob/bb84ac2714b82f7df125855cb0949066eb10cbf5/couchbase.c#L914 and does not set bytes as nullable

We could try making our own encoder/decoder

$this->bucket->setTranscoder(
            function ($value) {
                return array(serialize($value), 0, 0);
            },
            function ($value, $flags, $datatype) {
                /** @noinspection UnserializeExploitsInspection */
                return unserialize($value);
            }
        );

srjlewis avatar Oct 15 '24 20:10 srjlewis

@Geolim4 Let me dive into that, thanks! Maybe add a deprecated warning for V3 then ?

Indeed, I should have deprecated it sooner, at least at the release of 9.2, since the Couchbasev4 was released and nicely co-maintained by @srjlewis

Geolim4 avatar Oct 15 '24 20:10 Geolim4

I have also check the upgrade path of the OS Alpine 3.16 and the OS is EOL as well as of 2024-05-23

Alpine 3.16 does have a package for SDK v4, but since it is the very first version of the v4 SDK, I would say "use at your own risk" https://pkgs.alpinelinux.org/package/v3.16/community/x86_64/php81-pecl-couchbase

srjlewis avatar Oct 15 '24 20:10 srjlewis

@Geolim4 Let me dive into that, thanks! Maybe add a deprecated warning for V3 then ?

Indeed, I should have deprecated it sooner, at least at the release of 9.2, since the Couchbasev4 was released and nicely co-maintained by @srjlewis

No worries, now we did deprecate it all together :smile: (I remembered you did in the past!)

Fabbzz avatar Oct 15 '24 20:10 Fabbzz

I have also check the upgrade path of the OS Alpine 3.16 and the OS is EOL as well as of 2024-05-23

Alpine 3.16 does have a package for SDK v4, but since it is the very first version of the v4 SDK, I would say "use at your own risk" https://pkgs.alpinelinux.org/package/v3.16/community/x86_64/php81-pecl-couchbase

You see issues with it ?? (Sorry for the extra reply)

Fabbzz avatar Oct 15 '24 20:10 Fabbzz

I see there has been a lot of changes and bug fixes between v4.0.0 to v4.2.3 so I cant predict what issues you could encouter, I have done my best to make the v4 driver within phpfastcache work with all versions of v4 that we could test with. https://github.com/couchbase/couchbase-php-client/releases

You could always give it a try and see what success you have. or the other option is to turn off deprcations within PHP and then look at a migration to a up to date web stack.

srjlewis avatar Oct 15 '24 20:10 srjlewis

@srjlewis Yes indeed and with docker; it's easy to just fire another 3.20+ Alpine container!

Fabbzz avatar Oct 15 '24 21:10 Fabbzz

@Fabbzz If you are able to fire a 3.20+ container easily and use it (not all poeple have that option), that would be great and if you need a hand with thw v4 driver, drop me a message.

srjlewis avatar Oct 15 '24 21:10 srjlewis

@srjlewis Happily I am indeed! I build all my own images because of legacy which I don' t want or sometimes need.

Fabbzz avatar Oct 15 '24 21:10 Fabbzz

Hi guys, I've just read through the thread, did I got it right that there is nothing blocking the work of fastcache if it is using couchbase library v4?

If the data should be treated as just bytes, you can use \Couchbase\RawBinaryTranscoder. It will not modify your payload and just mark it as a binary for the server. If you have your payload as JSON already and want to avoid double-encoding with default transcoder, you can use \Couchbase\RawJsonTranscoder.

avsej avatar Oct 21 '24 19:10 avsej

Hi @avsej

Our v4 driver is having no issues and does not have this issue. The OP is use couchbase v3 and our v3 driver with PHP 8.1

PHP 8.1 introduce a RFC Deprecate passing null to non-nullable arguments of internal functions and within the couchbase v3 SDK it is doing a internal call.

The deprcation warning is only being raised when a document does not exist.

The deprication is being raised on the following line within our v3 driver. https://github.com/PHPSocialNetwork/phpfastcache/blob/8cadd6fe80e1375b77d3a9a11702cb9c96776f55/lib/Phpfastcache/Drivers/Couchbasev3/Driver.php#L117 Before PHP 8.1 the the $document->content() would return a false value without a deprication warning.

within the v4 driver we are able to check for the error, but the error method does not exist in the v3 SDK https://github.com/PHPSocialNetwork/couchbasev4-extension/blob/65f0c77cbd497734c7eda2fbd272b2e5ebb9912e/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php#L250

The transcoder you to point to are in the v4 SDK is there the equivalate within the v3 SDK and would it advoid the internal call on a non existant document when calling the ```$document->content()`` method?

srjlewis avatar Oct 21 '24 19:10 srjlewis