shivas / versioning-bundle

Simple way to version (semantic versioning 2.0.0) your Symfony2/3/4/5/6 application
MIT License
112 stars 30 forks source link

Symfony cache: Version object cannot be cached #39

Closed permanovd closed 5 years ago

permanovd commented 5 years ago

Bundle version: ^3.1 Symfony version: 4.2

Version object cannot be exported to file cache.

It happens because Symfony\Component\VarExporter\Internal\Registry::getClassReflector throws NotInstantiableTypeException if class is not instantiable.

Error message:

[2019-01-10 13:42:12] cache.WARNING: Failed to save key "version" (Version\Version) {"key":"version","type":"Version\Version","exception":"[object] (Symfony\Component\Cache\Exception\InvalidArgumentException(code: 0): Cache key \"version\" has non-serializable Version\Version value. at /home/d/source/releases/3/vendor/symfony/cache/Traits/PhpFilesTrait.php:171, Symfony\Component\VarExporter\Exception\NotInstantiableTypeException(code: 0): Type \"Version\Version\" is not instantiable. at /home/d/source/releases/3/vendor/symfony/var-exporter/Internal/Registry.php:76)"} []

refs #30

metalmini commented 5 years ago

Same here, whats up with that?

Nogrod commented 5 years ago

looks like issue is in the dependency nikolaposa/version since the Version class is not serializable

as a temporary fix i've used https://github.com/Nogrod/version/commit/56c9a7b3477d68d25ca58f7e3a0b6f8fa9bef0d5

nikolaposa commented 5 years ago

Native PHP serialization/deserialization of a Version object works. I've just added a test case to cover it: https://github.com/nikolaposa/version/blob/master/tests/VersionTest.php#L139. I believe this is something specific to Symfony Cache or perhaps this TraceableAdapter that is in use here, because other, such as RedisAdapter do native serialization before persisting cache values.

jbtronics commented 5 years ago

It seems that this bug was fixed by a fix in the symfony var-dumper component (https://github.com/symfony/symfony/commit/e354d54e7edf13381056d5002b7807f476a9e8bc#diff-bc7a0b9933d7688a76f788080f091a11).

So no more warning since 4.2.7

shivas commented 5 years ago

closing this issue then