Problem/Motivation
When upgrading from UI Patterns version 1.x to 2.x in an existing project, I successfully migrated my existing patterns using the ui-patterns:migrate Drush command (thanks to the ui_patterns_legacy submodule). However, after completing the migration, my website went down, displaying the following error:
Le site Web a rencontré une erreur inattendue.
LogicException: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection. Adjust your code so that is not necessary. Alternatively, look at DependencySerializationTrait as a temporary solution. in Drupal\Core\Database\Connection->__sleep() (line 1920 of core/lib/Drupal/Core/Database/Connection.php).After investigating, I discovered that the error was caused by all components with props of the enum type.
Steps to reproduce
Migrating from UI patterns 1.x to UI patterns 2.x and use components with props type enum.
Proposed resolution
The EnumPropType plugin class (located in src/Plugin/UiPatterns/PropType/EnumPropType.php) should use DependencySerializationTrait trait to ensure proper serialization.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3471426-fix-ui-patterns-enum-serialization.patch | 1.58 KB | b.khouy |
Issue fork ui_patterns-3471426
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
b.khouyComment #3
b.khouyComment #4
b.khouyComment #5
b.khouyComment #6
pdureau commentedThanks a lot Brahim. Can you do a MR instead of a patch?
Why would
EnumPropTypebe the only one needingDependencySerializationTrait?Comment #7
b.khouyI'm not sure if this also affects other complex prop types, as I only have a few components in my project, and they all use primitive prop types (boolean, string, etc.) and enum prop type.
I will test with other prop types and create a merge request.
Comment #9
b.khouyI tested all existing prop types and found no serialization errors. This makes sense since, for example, the variant prop type uses enums, so fixing the issue with the enum prop type should also resolve it for the variant.
A merge request has been opened.
Comment #10
pdureau commentedI am not sure about this sentence.
This is the most important, I will do the review
Comment #11
christian.wiedemann commentedThe trait DependencySerializationTrait solves two seralization issues. (Correct me if I am wrong.) First if the plugin uses services and second if the plugin uses the translateable markup. EnumPropType uses translateable markup so this is propable the reason for the bug because summary method uses translateable markup.
So I would move this PropTypePluginBase.
Comment #12
pdureau commentedBrahim, can you move the trait use to PropTypePluginBase?
Comment #13
b.khouy@christian.wiedemann
You're right, it would be better to handle this in PropTypePluginBase, ensuring a general fix for all prop types.
@pdureau I'll take care of it.
Comment #14
b.khouyComment #15
b.khouyComment #16
pdureau commentedPHPCS is KO
Careful ( I have rebased the branch on git.drupalcode.org, you may need to delete and repull your local)
Comment #17
b.khouyComment #18
pdureau commentedComment #20
pdureau commented