Skip to content

[Cache] Failed to save key of type array #44138

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

Closed
adrienfr opened this issue Nov 19, 2021 · 23 comments · Fixed by #44188
Closed

[Cache] Failed to save key of type array #44138

adrienfr opened this issue Nov 19, 2021 · 23 comments · Fixed by #44188

Comments

@adrienfr
Copy link
Contributor

Symfony version(s) affected

5.4.0-BETA3

Description

When testing SF 5.4, the following warning occurs on entities with Assert annotations and PhpFilesAdapter cache.

Failed to save key "App%5CEntity%5CPartner%24name" of type array: Cache key "App%5CEntity%5CPartner%24name" has non-serializable "array" value.

How to reproduce

class Partner
{
    /**
     * @var int
     *
     * @ORM\Column(name="id_partner", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $idPartner;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=50)
     * @Assert\NotBlank
     * @Assert\Length(
     *     min=2,
     *     max=50,
     *     minMessage="partner.name.min_size",
     *     maxMessage="partner.name.max_size"
     * )
     */
    private $name;
...
}

Possible Solution

No response

Additional Context

[
  "key" => "App%5CEntity%5CPartner%24name"
  "exception" => Symfony\Component\Cache\Exception\InvalidArgumentException {#3436 ▼
    #message: "Cache key "App%5CEntity%5CPartner%24name" has non-serializable "array" value."
    #code: 0
    #file: "/var/www/morningcroissant/symfony/vendor/symfony/cache/Adapter/PhpFilesAdapter.php"
    #line: 229
    -previous: ErrorException {#3429 …}
    trace: {▶}
  }
  "cache-adapter" => "Symfony\Component\Cache\Adapter\PhpFilesAdapter"
]
@nicolas-grekas
Copy link
Member

Can you please share a small reproducing app?

@adrienfr
Copy link
Contributor Author

Can you please share a small reproducing app?

Here is a small reproducer.
Steps to reproduce :

  • composer install
  • symfony server:start
  • php bin/console doctrine:migrations:migrate
  • Go to http://127.0.0.1:8000/index
  • Open DebugBar and see Warnings

Capture d’écran 2021-11-19 à 11 58 06

@nicolas-grekas
Copy link
Member

I mean an app that I could install myself on my local machine please?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Nov 19, 2021

OH I missed the link, let me try it now!

@nicolas-grekas
Copy link
Member

I'm not able to reproduce the issue, I see no warning here :(

@adrienfr
Copy link
Contributor Author

I'm not able to reproduce the issue, I see no warning here :(

Could you try with PHP 7.3?

php -v
PHP 7.3.29-to-be-removed-in-future-macOS (cli) (built: Sep  6 2021 05:14:39) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.29, Copyright (c) 1998-2018 Zend Technologies

@nicolas-grekas
Copy link
Member

Same with this, no issue:
PHP 7.3.31-2+ubuntu20.04.1+deb.sury.org+1 (cli) (built: Oct 22 2021 12:34:45) ( NTS )

@adrienfr
Copy link
Contributor Author

That was my only lead that could have explained the difference :/

@nicolas-grekas
Copy link
Member

You might want to debug/dump the value that fails to be serialized and figure out where it comes from...

@adrienfr
Copy link
Contributor Author

adrienfr commented Nov 19, 2021

Already tried but couldn't trace why this can't be serialized :

PhpFilesAdapter.php on line 229:
array:3 [▼
  0 => Doctrine\ORM\Mapping\Column {#468 ▼
    +name: "name"
    +type: "string"
    +length: 50
    +precision: null
    +scale: null
    +unique: false
    +nullable: false
    +options: []
    +columnDefinition: null
  }
  1 => Symfony\Component\Validator\Constraints\NotBlank {#469 ▼
    +message: "This value should not be blank."
    +allowNull: false
    +normalizer: null
    +payload: null
    +groups: array:1 [▶]
  }
  2 => Symfony\Component\Validator\Constraints\Length {#499 ▼
    +maxMessage: "partner.name.max_size"
    +minMessage: "partner.name.min_size"
    +exactMessage: "This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters."
    +charsetMessage: "This value does not match the expected {{ charset }} charset."
    +max: 50
    +min: 2
    +charset: "UTF-8"
    +normalizer: null
    +allowEmptyString: false
    +payload: null
  }
]

@adrienfr
Copy link
Contributor Author

It somehow seems like this is related to groups not explicitly defined in @Assert. With the following code, there is no more issues:

/**
* @var string
*
* @ORM\Column(name="name", type="string", length=50)
* 
* @Assert\NotBlank(groups="Default")
* @Assert\Length(groups="Default",
*     min=2,
*     max=50,
*     minMessage="partner.name.min_size",
*     maxMessage="partner.name.max_size"
* )
*/

@adrienfr
Copy link
Contributor Author

adrienfr commented Nov 19, 2021

@nicolas-grekas just to double-check, you don't have any warnings at all?
Capture d’écran 2021-11-19 à 14 33 30

Because with new Profiler re-design, warning are not displayed on main page:
Capture d’écran 2021-11-19 à 14 33 36

I have to click on "All messages" to display warnings:
Capture d’écran 2021-11-19 à 14 33 43

@stof
Copy link
Member

stof commented Nov 19, 2021

@nicolas-grekas could it be related to aa4fb0c#diff-eadef5e494fbfb85346e70992f4b18994df0b999b7d336c9cece5ab9e9a4a18a unsetting the property ?

@adrienfr
Copy link
Contributor Author

Thanks @stof for this lead!
I confirm that there is no more warnings when I comment //unset($this->groups); and re-add $knownOptions['groups'] = true; in Constraint.php on both my reproducer and my app

Capture d’écran 2021-11-19 à 15 00 13

Capture d’écran 2021-11-19 à 14 55 16

@nicolas-grekas
Copy link
Member

@nicolas-grekas just to double-check, you don't have any warnings at all?

I confirm I have nothing like that. Anyone else reproducing?

@adrienfr can you please debug the situation a bit more, at least show us the details of the previous ErrorException?

@adrienfr
Copy link
Contributor Author

adrienfr commented Nov 19, 2021

@nicolas-grekas could this be helpful?

Capture d’écran 2021-11-19 à 16 12 51

I'm available on Slack (Symfony Devs), username adrienfr if you need

@nicolas-grekas
Copy link
Member

I would really need the "previous" exception.

@adrienfr
Copy link
Contributor Author

I would really need the "previous" exception.

"User Notice: serialize(): "groups" returned as member variable from __sleep() but does not exist"

@adrienfr
Copy link
Contributor Author

Found this related issue but you might remember :) #28352

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Nov 19, 2021

OK, I now am able to reproduce. I need to run bin/console c:c --no-warmup before refreshing the browser.

@PhilETaylor
Copy link
Contributor

Tagging my stack trace #44182 as it seems to be relevant

nicolas-grekas added a commit that referenced this issue Nov 22, 2021
…when __sleep() is implemented (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[VarExporter] fix exporting declared but unset properties when __sleep() is implemented

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #44138 Fix #44182
| License       | MIT
| Doc PR        | -

Best reviewed [ignoring whitespaces](https://github.com/symfony/symfony/pull/44188/files?w=1).

Commits
-------

a557bdc [VarExporter] fix exporting declared but unset properties when __sleep() is implemented
@nicolas-grekas
Copy link
Member

Thanks for the details.

@adrienfr
Copy link
Contributor Author

Thanks @nicolas-grekas

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