Problem/Motivation

After upgrading to the most recent version (8.x-1.22), my application is logging `This could not be unserialized` errors with '%value' equal to 'a:0:{}'. This seems to be caused by a 's:12:"dependencies";a:0:{}' pair being present in my metatag configuration values.

Steps to reproduce

Not sure on the exact reproduction; it has appeared after upgrading.

Version info

PHP 8.1.11
Drupal 9.4.7
Metatag 8.x-1.22

Proposed resolution

Allow deserialization of empty arrays without error logs where possible.

Comments

JesperN created an issue. See original summary.

jnoordsij’s picture

Issue summary: View changes
damienmckenna’s picture

Does the problem go away if you edit and re-save the global default settings?

jenger1965’s picture

I have the same problem with lots of "This could not be unserialized: a:0:{}" error messages in the wd log.
Resaving of the global settings does not help.

In MetatagManger->getFieldTags(): An serialized empty array "a:0:{}" should be handled as empty string.
Not enter the if (!empty($new_tags)) path

$serialized_value = $item->get('value')->getValue();
      if (!empty($serialized_value)) {
        $new_tags = unserialize($serialized_value);
        if (!empty($new_tags)) {
          if (is_array($new_tags)) {
            $tags += $new_tags;
          }
          else {
            $this->logger->error("This was expected to be an array but it is not: \n%value", ['%value' => print_r($new_tags, TRUE)]);
          }
        }
        else {
          $this->logger->error("This could not be unserialized: \n%value", ['%value' => print_r($serialized_value, TRUE)]);
        }
      }
jenger1965’s picture

$new_tags = unserialize($serialized_value);
can return FALSE if unserialize() fails.
Maybe it makes sense to differ between FALSE and an empty array at
if (!empty($new_tags)) {

jenger1965’s picture

This patch work for me...

damienmckenna’s picture

Version: 8.x-1.22 » 8.x-1.x-dev
Status: Active » Needs review

Thanks for working out a possible patch, let's see how it works with the testbot.

wells’s picture

StatusFileSize
new1.19 KB

I'm also seeing this issue. The #6 patch had the wrong base. Attaching an updated patch here.

flocondetoile’s picture

I saw too a lot of errors in the logs since I upgraded metatag to 8.x-1.22.

Oct 11 00:02:44 mysite-prod-vm1 mysite: http://www.mysite.fr:443|1665439364|metatag|213.56.203.85|http://www.mysite.fr:443/fr/taxonomy/term/183/feed||0||This could not be unserialized:
Oct 11 00:02:44 mysite-prod-vm1 mysite: a:0:{}
Oct 11 00:04:10 mysite-prod-vm1 mysite: http://www.mysite.fr|1665439450|metatag|92.247.181.31|http://www.mysite.fr/fr/taxonomy/term/336/feed|https://www.mysite.fr/|0||This could not be unserialized:
Oct 11 00:04:10 mysite-prod-vm1 mysite: a:0:{}

Patch #8 fix the issue.

othermachines’s picture

Patch #8 resolves the error for me (using metatag 8.x-1.22) - thanks!

damienmckenna’s picture

Parent issue: » #3313052: Plan for Metatag 8.x-1.23
StatusFileSize
new1.02 KB

Thank you for the reviews.

This has a minor tidying of the changes.

  • DamienMcKenna committed b81b42a on 8.x-1.x
    Issue #3313273 by DamienMcKenna, jenger1965, wells, JesperN,...
damienmckenna’s picture

Status: Needs review » Fixed

Committed. Thanks everyone!

Status: Fixed » Closed (fixed)

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