Versioned::get_version removes fields with null values

Silverstripe Version: 4.5

I’m either using this wrong/expectations are wrong or maybe this is a bug.

$allVersions = $myRecord->Versions('', 'ID DESC', 2);


^ Shows all fields for the last two versions retrieved. Good.

$to   = Versioned::get_version(MyRecord::class, $myRecord->ID, $allVersions[0]->Version);
$from = Versioned::get_version(MyRecord::class, $myRecord->ID, $allVersions[1]->Version);


Get the last two versions and dump them and fields with NULL values are missing that are in $AllVersions.

When adding a value to a previously empty field, the $to dump contains the field and the data.
The $from dump however doesn’t contain the field at all (it had a null value).

I’m using the DataDifferencer($from, $to); to show changes. When adding a value to a field that was empty it shows no changes as the field isn’t in the list.

The field I’m seeing this on is just a Varchar.

Update. Might be more related to DataDifferencer…

diffedData starts off with

if ($this->fromRecord) {
    $diffed = clone $this->fromRecord;
    $fields = array_keys($diffed->toMap() + $this->toRecord->toMap());

Whereas ChangedFields has:

if ($this->fromRecord) {
    $base = $this->fromRecord;
    $fields = array_keys($this->fromRecord->toMap());


Applying the change to ChangedFields finally seems to work.

Love to know what the deal is though.