Problem/Motivation
During the modification of a taxonomy term text field by adding or removing a "0" as first character if it is the only change, it isn't saved. The problem is the same with the other entities (Node, User).
Examples :
- Changing 01 to 1, stay 01.
- Changing 1 to 01, stay 1.
- Changing 01 to 2, work 2 is saved.
Steps to reproduce
Create a taxonomy with a text field, create an instance with the value "01" save. Then modify, change the value to 1, save.
Proposed resolution
On the save process, change the equals test to take this 0 into account.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet

Comments
Comment #2
cilefen commentedPlease list out the full steps to reproduce, including exactly how to set up the field. Thank you!
Also, Drupal 8 is no longer supported so be sure to test this on Drupal 9.
Comment #3
LouisCCAusy commentedThe test has been made with Drupal 9.3.3 and 9.4.x-dev and the error persist.
Steps to reproduce :
- Create a new entity type (Taxonomy, Node or User)
- Add new field text (plain), with default configuration
- Create a new entity
- Set value to 01, save
- Change value to 1, save
The values stays 01.
Comment #4
larowlanThanks
Comment #7
nicolas.hod commentedHi,
We are facing the same issue.
We have a text plain field in taxonomy terms.
starting value : 1400 ; changed to 01400 => saved value 1400
starting value : 1400 ; changed to 001400 => saved value 1400
starting value : 1400 ; changed to 11400 => saved value 11400
starting value : 11400 ; changed to 01400 => saved value 01400
starting value : 01400 ; changed to 1400 => saved value 01400
Thx,
Comment #8
enaznin commented@nicolas.hod what is your drupal version?
Tested on 9.5.3 and 10.1.0-dev , could not reproduce. followed the steps mentioned on #3.
Comment #10
mericone commentedI am experiencing the same issue as @nicolas.hod described above. It seems as if Drupal or PHP checks the value before saving and ignores a leading zero as a change.
Drupal 9.5.10, a simple textfield (string) which was used to enter a number with leading 0, no extra field modules installed, PHP 8.1.13
Comment #11
happypanda commentedI'm also seeing the same bug - in a text field being used for phone numbers attached to user accounts.
Drupal 9.5.2
Comment #12
happypanda commentedUpdate:
Bug is still there with in the following config:
Drupal Version: 9.5.10
Web Server: LiteSpeed
PHP Version 8.1.18: (more information)
Memory limit: 1024M
Database Version: 8.0.33
System: MySQL, Percona Server, or equivalent
I've added a text field to users ( /admin/config/people/accounts/fields ) for phone number.
Using Module: "field formatter pattern" 1.0.0 with the following pattern: "[0-9]{8,10}"
(Note I have tested without the field formatter pattern and the problem still exists
To replicate:
- Add a user, give them a phone number of "12345678". Save
- Edit that user again.
- Change the phone number to "012345678". Save.
- Note that the phone number has not changed and is still "12345678".
Comment #13
drctrue commentedHi,
we're facing the same issue with Text (plain) fields used for phone numbers.
Drupal 9.5.10
PHP 8.1.16
Comment #14
mnico commentedI have a similar problem. With a string field I save the value
100.0and then edit it to100, the new value is not saved (the same happens inversely). This occurs only when saving content without creating a new revision.This happens to me in Drupal 10.1
Reviewing the code I found the following:
In the
core/lib/Drupal/Core/Field/FieldItemList.phpclass there is the "equals" method:With the previous example we would be comparing at the end:
And this would return true, which means it should not be updated. It is solved if "===" is placed but I don't know if this would affect it in general.
Comment #15
mnico commented#8 To reproduce this you must update the entity without creating a new revision. Otherwise it will update it.
Comment #16
mnico commentedThe "equals" method would be designed to indicate that the value 2 and '2' (string) are equal. This is according to what I see in the FieldItemListTest tests. For this reason '02' and '2' or '2.0' and '2' would also be considered "equal" when it should not be for the String field in my opinion.
I think a solution would be that in the "equals" method, transform the values that are numeric to string and end up doing the strict comparison, something like this:
Comment #20
mnico commentedComment #21
smustgrave commentedCan you please update MR to 11.x
Before anyone opens a new one lets try and update the existing one first.
Comment #23
mnico commentedMy mistake, I tried to update the existing one but I had already created a new one.
Comment #24
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #25
wotts commentedWe ran into the very same issue.
Confirmed that 5633.patch works and resolves this issue!
Comment #26
happypanda commentedPatch 5633 works for me as well, when manually applied to Drupal 9.5.10.
Thanks!
Comment #27
akoe commentedPatch from MR 5633 works and applied with core 10.2.5 as well as with 11.0.0-alpha1.
Comment #28
robertoperuzzoI applied the patch MR 5633 in a Drupal Commerce project (D10.0.11) and I have some problems running our custom Kernel tests. In particular, when we create a commerce_order sample containing a couple of order_items the test fails with the message "Test was run in the child process and ended unexpectedly".
Debugging with xDebug I get the message "Error: Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '256' frames".
I think it is related to the double reference between order and order_item:
1. in the order we have the entity reference to the order_items
2. in the order_item we have the entity reference to the order
Probably, the recursive walk in the patch
drives crazy the order creation.
Comment #29
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #30
matdemeuePatch 5633 worked for me on Drupal 10.3.1.
In our case it was not a leading 0 but a trailing 0 on a field for a custom entity.
Problem solved by applying the patch.
Comment #31
volegerUploaded MR 5633 as a patch