0

After upgrading Magento 2 to version 2.2.3 the php bin/magento setup:upgrade stopped working and throws error Failure reason: 'Unable to unserialize value.' Things I have already triex to do...

1: Remove cache:

php rm -rf var/di/* var/generation/* var/cache/* var/page_cache/* var/view_preprocessed/* var/composer_home/cache/*

2: Grant Permissions:

find . -type f -exec chmod -c 644 {} \; && find . -type d -exec chmod -c 755 {} \; ||||| Working

3: Deploy Static Content:

php bin/magento setup:static-content:deploy -f

4: Compile:

php bin/magento setup:di:compile

But none of the above worked. Any suggestions? Your help would be very much appreciated.

  • Can I ask you to provide the full stack trace? (add -vvv to bin/magento for this ) – KAndy Mar 4 '18 at 8:59
  • Hi @kandy ! Thanks for the help. Here's the screenshot of the error I receive when I run "bin/magento setup:upgrade". Screenshot here: prntscr.com/inudsd – P. Paul Mar 7 '18 at 20:33
0

If you are getting this from custom module Please check following answer.

As per Magento 2.2 Release Note

Security enhancements

In general, we’ve removed serialize/unserialize from most the code to improve protection against remote code execution attacks. We’ve enhanced protection of code where use of object serialization or unserialization was unavoidable. Additionally, we’ve increased our use of output escaping to protect against cross-site scripting (XSS) attacks.

So you need to inject \Magento\Framework\Serialize\Serializer\Json class for serialize and unserialize values.

use following code for serialize and unserialize values.

protected $serialize;

public function __construct(
    \Magento\Framework\Serialize\Serializer\Json $serialize
) {
    $this->serialize = $serialize;
}

public function serialize($value){
    return $this->serialize->serialize($value);
}

public function unserialize($value){
    return $this->serialize->unserialize($value);
}
  • Hi @chander-shekhar ! Thanks for the help. After replacing the code in the json.php file with the above code you provided, when I ran the command "bin/magento setup:upgrade" I got the error in the following screenshot: prntscr.com/inc307 . To be clear, please check the following the screenshot also to see the serialization error I was getting when I run "bin/magento setup:upgrade" before. Screenshot here: prntscr.com/inc5gx . Thank for your help! – P. Paul Mar 5 '18 at 22:29
  • Where should I put those serlialize/unserialize methods? In which file? – StR Oct 4 '18 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.