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
This was found in #2841291: Fix NOT NULL handling in the entity storage and 'primary key' changes when updating the storage definition of an identifier field.
If a migration source references an entity ID that does not exist, an appropriate entity will be stubbed. If that entity is a content entity with a required field with a default value, the stubbed entity will not have that default value applied to the field.
That is because the default value is incorrectly nested in another array, so during entity-saving the value ultimately gets lost.
Proposed resolution
Remove the unnecessary and incorrect nesting.
Comment | File | Size | Author |
---|---|---|---|
#9 | 2923915-9.patch | 4.78 KB | tstoeckler |
#9 | 2923915-5-9-interdiff.txt | 3.34 KB | tstoeckler |
Comments
Comment #2
tstoecklerHere we go.
Comment #5
tstoecklerSelf-review:
Seems kind of pointless to go into a loop here,
EntityTestMul::load(reset($ids))
would make more sense.For extra credit, fetch the default value from the field definition.
Fixed the above and fixed up the test a bit more, as well.
EDIT: Apparently this does not apply to 8.4.x. But attaching 8.5.x patches for now. Will reroll for both branches when this is RTBC.
Comment #7
heddnAssigning to myself to review for the week up coming.
Comment #8
heddnCan we add a test for a field with a cardinality of > 1? I'd like to see what happens when we provide multiple default values. Does it need to be an array then?
Comment #9
tstoecklerSure, no problem. Added another test. Actually it will work just fine with multiple values as well, so the test change is the only needed change.
Comment #10
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedLooks good to me :)
Comment #11
heddn+1 from me too. Thanks for the added test coverage.
Comment #15
catchCommitted/pushed to 8.6.x and cherry-picked to 8.5.x. Thanks!