[2.0.0-beta2] Enum prop type serialization issue

Created on 31 August 2024, 3 months ago
Updated 8 September 2024, 2 months ago

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.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡²πŸ‡¦Morocco b.khouy πŸ‡²πŸ‡¦ Morocco

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @b.khouy
  • πŸ‡²πŸ‡¦Morocco b.khouy πŸ‡²πŸ‡¦ Morocco
  • πŸ‡²πŸ‡¦Morocco b.khouy πŸ‡²πŸ‡¦ Morocco
  • Status changed to Needs review 3 months ago
  • πŸ‡²πŸ‡¦Morocco b.khouy πŸ‡²πŸ‡¦ Morocco
  • Issue was unassigned.
  • πŸ‡²πŸ‡¦Morocco b.khouy πŸ‡²πŸ‡¦ Morocco
  • Status changed to Needs work 3 months ago
  • πŸ‡«πŸ‡·France pdureau Paris

    Thanks a lot Brahim. Can you do a MR instead of a patch?

    Why would EnumPropType be the only one needing DependencySerializationTrait?

  • πŸ‡²πŸ‡¦Morocco b.khouy πŸ‡²πŸ‡¦ Morocco

    I'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.

  • Pipeline finished with Failed
    3 months ago
    Total: 276s
    #270891
  • Pipeline finished with Success
    3 months ago
    Total: 268s
    #270895
  • Status changed to RTBC 3 months ago
  • πŸ‡²πŸ‡¦Morocco b.khouy πŸ‡²πŸ‡¦ Morocco

    I 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.

  • Assigned to pdureau
  • Status changed to Needs review 3 months ago
  • πŸ‡«πŸ‡·France pdureau Paris

    the variant prop type uses enums, so fixing the issue with the enum prop type should also resolve it for the variant.

    I am not sure about this sentence.

    I tested all existing prop types and found no serialization errors.

    This is the most important, I will do the review

  • πŸ‡©πŸ‡ͺGermany Christian.wiedemann

    The 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.

  • Issue was unassigned.
  • Status changed to Needs work 2 months ago
  • πŸ‡«πŸ‡·France pdureau Paris

    Brahim, can you move the trait use to PropTypePluginBase?

  • πŸ‡²πŸ‡¦Morocco b.khouy πŸ‡²πŸ‡¦ Morocco

    @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.

  • Assigned to b.khouy
  • πŸ‡²πŸ‡¦Morocco b.khouy πŸ‡²πŸ‡¦ Morocco
  • Pipeline finished with Canceled
    2 months ago
    Total: 115s
    #274669
  • Issue was unassigned.
  • Status changed to Needs review 2 months ago
  • πŸ‡²πŸ‡¦Morocco b.khouy πŸ‡²πŸ‡¦ Morocco
  • Pipeline finished with Failed
    2 months ago
    Total: 236s
    #274671
  • Status changed to Needs work 2 months ago
  • πŸ‡«πŸ‡·France pdureau Paris

    PHPCS is KO

       | ERROR | [x] Use statements should be sorted alphabetically. The first
       |       |     wrong one is
       |       |     Drupal\Component\Plugin\Definition\PluginDefinitionInterface.
       |       |     (SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses.IncorrectlyOrderedUses)
    

    Careful ( I have rebased the branch on git.drupalcode.org, you may need to delete and repull your local)

  • Pipeline finished with Canceled
    2 months ago
    Total: 89s
    #276631
  • Pipeline finished with Failed
    2 months ago
    Total: 266s
    #276632
  • Pipeline finished with Success
    2 months ago
    Total: 259s
    #276649
  • Status changed to Needs review 2 months ago
  • πŸ‡²πŸ‡¦Morocco b.khouy πŸ‡²πŸ‡¦ Morocco
  • Status changed to Fixed 2 months ago
  • πŸ‡«πŸ‡·France pdureau Paris
  • Status changed to Fixed 2 months ago
  • πŸ‡«πŸ‡·France pdureau Paris
Production build 0.71.5 2024