Problem/Motivation

On Drupal version 10.2.x+ encrypted decimal field values are no longer being saved.

This bug stems from a new decimal primitive data type that was added in 10.2.0 (https://www.drupal.org/node/3376447). The decimal data type is not handled by the switch statement in \Drupal\field_encrypt\ProcessEntities::getUnencryptedPlaceholderValue , therefore this method returns NULL. This results in the field value getting set to NULL.

The value is still successfully encrypted and stored in encrypted_field_storage, however, when the entity is decrypted the stored value is not applied. This is because $field->getValue() returns an empty array so the field properties are not updated in \Drupal\field_encrypt\ProcessEntities::setEncryptedFieldValues.

Steps to reproduce

  1. Set up a Content Type with a encrypted Number (decimal) field.
  2. Create a node for that Content Type setting the decimal field value.
  3. The field value is not visible when viewing or editing the new node.

Proposed resolution

Update \Drupal\field_encrypt\ProcessEntities::getUnencryptedPlaceholderValue and add decimal data type to the switch statement.

CommentFileSizeAuthor
#3 3488771-encrypted-decimal-field-3.patch16.21 KBtame4tex
Command icon 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

tame4tex created an issue. See original summary.

tame4tex’s picture

I have created MR !73 to add both testing and a fix for this bug.

Modifying ProcessEntitiesTest was not enough to test for this bug as it seems this unit test is allowing unexpected results to slip through. I have added a separate issue for this #3488808: ProcessEntitiesTest is allowing unexpected results to slip through.

I therefore added Functional testing to ensure there is adequate coverage for this bug.

tame4tex’s picture

Status: Active » Needs review
ptmkenny’s picture

This was originally reported by pp.panatom in #3465540: Drupal 10.2 - field values on decimal fields getting lost, which I mistakenly closed-- I'm sorry for incorrectly closing that. However, I'm leaving that issue closed in favor of this one because this one has tests.

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

This looks good.

  • alexpott committed 401acf4f on 4.x
    Issue #3488771 by tame4tex, ptmkenny: Encrypted decimal field value not...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

  • alexpott committed 8f007f50 on 3.2.x
    Issue #3488771 by tame4tex, ptmkenny: Encrypted decimal field value not...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.