Problem/Motivation
Working on #2590993: Create stub entities with proper default values, when stubbing migration can pass NULL values for fields (as opposed to omitting them from the value array entirely) - ContentEntityStorageBase::doCreate() applied array_key_exists and thus considers those values to exist, skipping applyDefaultValue(). It seems to make sense to me to apply the default value when the current value is NULL, but maybe I'm missing something. So, submitting a patch to check is_null() - if this fails, that's good evidence use cases for the current behavior exist and we should probably let this go.
Proposed resolution
Also apply an is_null() check.
Remaining tasks
If this doesn't break any existing tests, add an explicit test.
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
handle-null-values.patch | 656 bytes | mikeryan | |
Comments
Comment #2
mikeryanComment #3
BerdirThat would then be just an isset().
I do think this is by design however. If you explicitly pass NULL, you don't want the default value, you want no value. Don't pass NULL if you want a default.
Would also be a behavior change at this point.
Comment #12
quietone CreditAttribution: quietone as a volunteer commented@mikeryan, hi!
I think this is a duplicate of an earlier issue, #1430454: Differentiate NULL and empty for default values. There is much more discussion over there as well.
Therefore, closing as a duplicate. If that is wrong, reopen the issue, by setting the status to 'Active', and add a comment.
Thanks!