8000 Failed to save key: User Notice: serialize(): \"groups\" returned as member variable from __sleep() but does not exist at · Issue #28352 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Failed to save key: User Notice: serialize(): \"groups\" returned as member variable from __sleep() but does not exist at #28352

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
yawa20 opened this issue Sep 4, 2018 · 3 comments

Comments

@yawa20
Copy link
yawa20 commented Sep 4, 2018

Symfony version(s) affected: 4.2.0-DEV

Description
on entity caching get`s an error:

cache.WARNING: Failed to save key "<entity_field_name_here>" (array) {"key":"<entity_field_name_here>","type":"array","exception":"[object] (Symfony\\Component\\Cache\\Exception\\InvalidArgumentException(code: 0): Cache key \"<entity_field_name_here>\" has non-serializable array value. at /vendor/symfony/cache/Traits/PhpFilesTrait.php:171, ErrorException(code: 0): User Notice: serialize(): \"groups\" returned as member variable from __sleep() but does not exist at /vendor/symfony/cache/Marshaller/PhpMarshaller/Marshaller.php:145)"} 

How to reproduce
add validation assertions to doctrine entity field without "groups" property, then try to build project
it happend because Constraints have lazily field ("groups"), and it does not exists before $value->__sleep() calls.

Possible Solution
in Marshaller::marshall() method call
$value->__sleep() before $arrayValue = (array) $value;

@yawa20 yawa20 closed this as completed Sep 4, 2018
@sroze
Copy link
Contributor
sroze commented Sep 4, 2018

@yawa20 would you be willing to share your resolution so it can help others in the future? :)

@yawa20
Copy link
Author
yawa20 commented Sep 5, 2018

@sroze
cache component was be upgraded and PhpMarshaller was removed.
so, bug in PhpMarshaller not exists.

but, my resolution was
"move $value->__sleep() call before $arrayValue = (array) $value;"

in Marshaller/PhpMarshaller.php

original code

            $sleep = null;
            $arrayValue = (array) $value;
            ...
            //some code here
            ...
             if (\method_exists($class, '__sleep')) {
                if (!\is_array($sleep = $value->__sleep())) {
                    trigger_error('serialize(): __sleep should return an array only containing the names of instance-variables to serialize', E_USER_NOTICE);
                    $value = null;
                    continue;
                }
                $sleep = array_flip($sleep);
            }

fixed code

           $sleep = null;
           if (\method_exists($class, '__sleep')) {
               if (!\is_array($sleep = $value->__sleep())) {
                  trigger_error('serialize(): __sleep should return an array only containing the names of instance-variables to serialize', E_USER_NOTICE);
                  $value = null;
                  continue;
               }
               $sleep = array_flip($sleep);
           }
           $arrayValue = (array) $value;
           ...
            //some code here
           ...

@nicolas-grekas
Copy link
Member

Actually that's a real bug! See #28352 for the fix.

nicolas-grekas added a commit that referenced this issue Sep 7, 2018
…() (nicolas-grekas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[VarExporter] fix exporting objects that mutate on __sleep()

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28352
| License       | MIT
| Doc PR        | -

Commits
-------

36e412f [VarExporter] fix exporting objects that mutate on __sleep()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0