Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
MetroConductor opened this issue Sep 28, 2024 · 20 comments
Assignees

Comments

@MetroConductor
Copy link

MetroConductor commented Sep 28, 2024

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 ?

  • I have searched over the Wiki
Copy link

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

@Geolim4
Copy link
Member

Geolim4 commented Oct 3, 2024

Ok, i'll take a look this weekend

@Fabbzz
Copy link

Fabbzz commented Oct 15, 2024

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

Thanks for reporting @MetroConductor

@Geolim4
Copy link
Member

Geolim4 commented Oct 15, 2024

@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()

$content = $document->content();

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)

@Fabbzz
Copy link

Fabbzz commented Oct 15, 2024

@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 : couchbase/couchbase-php-client#185

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

@Geolim4
Copy link
Member

Geolim4 commented Oct 15, 2024

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 :(

@Fabbzz
Copy link

Fabbzz commented Oct 15, 2024

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

@Geolim4
Copy link
Member

Geolim4 commented Oct 15, 2024

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

@Fabbzz
Copy link

Fabbzz commented Oct 15, 2024

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

@srjlewis
Copy link

srjlewis commented Oct 15, 2024

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);
            }
        );

@Geolim4
Copy link
Member

Geolim4 commented Oct 15, 2024

@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

@srjlewis
Copy link

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

@Fabbzz
Copy link

Fabbzz commented Oct 15, 2024

@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 😄 (I remembered you did in the past!)

@Fabbzz
Copy link

Fabbzz commented Oct 15, 2024

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)

@srjlewis
Copy link

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.

@Fabbzz
Copy link

Fabbzz commented Oct 15, 2024

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

@srjlewis
Copy link

@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.

@Fabbzz
Copy link

Fabbzz commented Oct 15, 2024

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

@avsej
Copy link

avsej commented Oct 21, 2024

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.

@srjlewis
Copy link

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.

$content = $document->content();

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants