Problem/Motivation
Depending on the state of the field, and which methods have been called, the return value of getValue() will be different.
Scenario
$field = User::load(1)->get('pass');
$value1 = $field->getValue();
$field->getProperties();
$value2 = $field->getValue();
Expected
$value1 === $value2
Actual
$value1 !== $value2
Proposed resolution
Switch from looping over $this->properties to $this->getProperties()
Remaining tasks
User interface changes
API changes
Data model changes
\Drupal\Core\TypedData\Plugin\DataType\Map::getValue()
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | 2934192-28-check-test-coverage.patch | 1.94 KB | amateescu |
| #15 | interdiff_13-15.txt | 511 bytes | vsujeetkumar |
| #15 | 2934192_15.patch | 10.58 KB | vsujeetkumar |
| #13 | 2934192-rerolled-13.patch | 10.37 KB | Vidushi Mehta |
| #2 | 2934192-properties-2.patch | 14.34 KB | tim.plunkett |
Issue fork drupal-2934192
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
tim.plunkettComment #4
berdirI'm not sure at all that this change is correct or that it is exposing bugs, more likey it is *causing* at least some of those test fails.
Some, maybe all places use $this->properties for two reasons as far as I know/remember:
a) An optimization, a property that was not initialized as a property object doesn't have an updated value, so we don't need to get it.
b) getProperties() does not return computed properties by default but I'm sure at least some of those calls rely on processing computed properties, things like updating them specifically need to reset computed properties, so that for example the processed text is recalculated if the value or the filter format changes.
I need to better understand what exactly the validation problem is with the other issue before I can further comment on it. I'm not saying there's nothing wrong but I'm quite sure that this is not the correct fix :)
Comment #5
eclipsegc commentedThe issue is we have a user (say... user 1) and when that user is validated by the typed data system, it loads the "unchanged entity" from the database. So now we have two copies of the same entity, but user1->pass and user2->pass don't have the same properties on them because getProperties() is never called against the unchanged entity which results in the validator's comparisons failing on password (even though they both have the same password value).
Eclipse
Comment #6
tim.plunkett\Drupal\user\Plugin\Validation\Constraint\ProtectedUserFieldConstraintValidator::validate()line 86:
$items->getValue()is$account_unchanged->get($field->getName())->getValue()isWhile the password value is identical, the comparison fails because the two other properties of
\Drupal\Core\Field\Plugin\Field\FieldType\PasswordItemare not present in one of the arrays.The original change to getValue (without the others to setValue, __clone, etc) fixed that bug.
Comment #12
andypostFresh list of modules to add filter dependency in #2413471-51: FieldItemBase must check property definitions instead of already instantiated properties
Comment #13
Vidushi Mehta commentedPatch rerolled.
Comment #15
vsujeetkumar commentedFixing Tests, Please review.
Comment #16
mxr576Fix comparison in ProtectedUserFieldConstraintValidator is related to #6
Comment #21
bradjones1I got bit by this today, via symptoms of #3123696: Fix comparison in ProtectedUserFieldConstraintValidator (agree, that may be a duplicate.)
This is a bit dated so I'll take a stab at a "re-roll" into an MR and see how it fares against 9.5.x.
Comment #23
bradjones1Transferred patches into an MR rebased on 9.5.x. Notable to anyone reviewing the history here, none of the "re-rolls" following the actual patch in #2 contained... the patch. So this seeks to consolidate everything here, since a lot of this requires test updates per #4.
Comment #24
bradjones1https://dispatcher.drupalci.org/job/drupal_patches/151438/testReport/jun...
Comment #25
bradjones1Comment #26
bradjones1So I generally concur with Berdir in #2
and got caught up in the symptoms of this issue today. I consider myself a pretty good Drupaller and I will totally concede that even after spending hours on this today, I still can't tell you the difference between "values" and "properties."
So I'm going to step back, however if you are coming to this from #3123696: Fix comparison in ProtectedUserFieldConstraintValidator I just posted an MR there to use
FieldItemList::equals()instead of PHP array comparison, which might very well be the correct answer for anyone running into this bug. That method contains much of the logic involved in working around this issue altogether and in a more eloquent way.Comment #28
amateescu commentedI'm curious to see what are the failing tests mentioned in those @todos.
Comment #29
bradjones1LOL... nothing?
Comment #30
amateescu commentedThis was most likely fixed by #2981889: Performance Degradation in Layout Builder and other places likely , so what's left to do here is clean up that dead code.
As for the initial scope of the issue, as @bradjones1 mentioned above in #26, if you need to compare field item objects you have to use their
equals()method.Comment #31
smustgrave commentedCan the issue summary be updated to include what's needed now. If it's cleaning up dead code if that could be documented please
Thanks.