Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When setting an entity reference field with target ID as integer and next to it provide the entity object an exception will be thrown.
Proposed resolution
The reason is that in EntityReferenceItem::setValue we do a type comparison:
$entity_id = $this->get('entity')->getTargetIdentifier();
...
$entity_id !== $values['target_id']
However $entity->id() returns the ID as a string, so the comparison will fail.
We should compare with "!=" instead of with "!==".
Remaining tasks
Review & Commit.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#20 | 2849861-d6-textarea-format-2-reroll.patch | 2.89 KB | joelpittet |
#9 | interdiff-3-9.txt | 1.13 KB | hchonov |
#9 | 2851149-9.patch | 2.48 KB | hchonov |
#3 | 2851149-3.patch | 2.15 KB | hchonov |
#2 | 2851149-2-PASS.patch | 2.03 KB | hchonov |
Comments
Comment #2
hchonovComment #3
hchonovI've been asked in IRC by @amateescu to put the code snippet to an existing test method, this is the only change to the PASS patch.
Comment #4
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedLooks great :)
Comment #6
Wim Leers/facepalm
I think it'd be good to add an explicit comment here about the use of a non-strict comparison.
Comment #7
catchYes let's add the comment. Or alternatively should we cast the result of $entity->id() somewhere beforehand?
Comment #8
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThat's a bit dangerous because entity IDs can be integers or strings, and I don't think looking at the base field definitions just for this cast is justifiable.
Comment #9
hchonovAdding a comment why we have to do a non-strict comparison.
Comment #10
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedNice :)
Comment #12
hchonovIt has been a CI error, therefore putting back to RTBC.
Comment #13
catchThis looks good to me, the @todos point to an issue that's close to ready but isn't going to make it into 8.3.x, whereas this still potentially could. Doesn't apply to 8.4.x though.
Comment #14
hchonov@catch, I've just tried to apply the patch and it applies on both 8.3.x and 8.4.x. I've put it for retesting once more for both 8.3.x and 8.4.x just in case.
Comment #15
hchonovIt looks like that the patch is applying as the tests are currently running, therefore I am removing the "Needs re-roll" tag and putting it back to RTBC as nothing has been changed on the patch.
Comment #16
alexpottCommitted 4bdfd06 and pushed to 8.4.x. Thanks!
Comment #18
alexpott@catch, @cilefen, @xjm and I just decided that patch rules apply to 8.3.x up until RC2 so we can back port this.
Committed 041b208 and pushed to 8.3.x. Thanks!
Comment #20
joelpittetComment #21
joelpittetWhoops wrong issue.