Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 298686

Custom serialized field's data should be normalized even if it's empty

$
0
0

Problem/Motivation

(Why the issue was filed, steps to reproduce the problem, etc.)
Problem:
- After 8.6.10 (SA-CORE-2019-003) there is an issue with site installation for sites that have default content which includes paragraphs. Paragraphs was also updated to 1.6 along with the above mentioned core security release. This release included a change in entity annotation to account for a new `serialized_field_property_names` annotation, which Paragraphs has set for its behavior_settings property in 1.6.

The code changes in hal, serialization modules'FieldItemNormalizer class don't seem to account for the serialized field's value being empty and has an if !empty check before serializing the data, which stops empty values being serialized. This leads to an unserialized empty array being handed to save to the database and there is an exception thrown:

InvalidArgumentException: Placeholders must have a trailing [] if they are to be expanded with an array of values. in /var/www/html/app/core/lib/Drupal/Core/Database/Connection.php:729                                               [error]

Steps to reproduce if you don't have an existing installation with default content:

  1. Install Drupal 8.6.10 using minimal profile with Paragraphs and Default Content latest
  2. Create new paragraph type (paragraph_text) with a single text field
  3. Create new content type (article) with a paragraph reference field
  4. Create new article content, add the paragraph_text and add some content and save.
  5. Create a new simple custom_content module with an info.yml and a content folder. Enable it.
  6. Export the content with default_content into the new module: drush dcer --folder="modules/custom_content/content" (replace the path if necessary)
  7. Export the site configuration into a sync folder
  8. Reinstall the site using the exported configuration: drush si --config-dir="path/to/config/sync" (Note: I had to manually delete the custom_content/content/user folder before installation as this throws a duplicate key error and is completely unrelated imho)

Expected result:
Site installs without exceptions thrown and the default content successfully imported from custom_content module.

Actual result:
Site installation fails and an exception is thrown:

InvalidArgumentException: Placeholders must have a trailing [] if they are to be expanded with an array of values. in /var/www/html/app/core/lib/Drupal/Core/Database/Connection.php:729                                               [error]

Known workarounds:
- Manually editing the exported content's json. Specifically the ones in the paragraphs folder, which have "behavior_settings" and its value set to an empty array. Removing the behavior_settings with empty values from the json of all exported paragraphs makes the site installation successful and produces the Expected result above.

Proposed resolution

The hal and serialization core modules' FieldItemNormalizer` should not check if a value is empty or not. Instead it should normalize/serialize the value regardless if it's empty, and only check if the array key exists. Attaching a patch

In 8.7.x this is handled using a common trait FieldableEntityNormalizerTrait in both modules and uses in_array to check. Currently in 8.6.x !empty is used to check whether to serialize the value or not.

Remaining tasks

(reviews needed, tests to be written or run, documentation to be written, etc.)

User interface changes

(New or changed features/functionality in the user interface, modules added or removed, changes to URL paths, changes to user interface text.)

API changes

(API changes/additions that would affect module, install profile, and theme developers, including examples of before/after code if appropriate.)

Data model changes

(Database or configuration data changes that would make stored data on an existing site incompatible with the site's updated codebase, including changes to hook_schema(), configuration schema or keys, or the expected format of stored data, etc.)

Release notes snippet

(Major and critical issues should have a snippet that can be pulled into the release notes when a release is created that includes the fix)

Original report by [username]

(Text of the original report, for legacy issues whose initial post was not the issue summary. Use rarely.)


Viewing all articles
Browse latest Browse all 298686

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>