New revision fields don't have a default value after making an entity revisionable

Created on 25 October 2022, about 2 years ago
Updated 5 July 2024, 6 months ago

Problem/Motivation

After making an entity type revisionable and visiting the revision overview of that entity, the page crashes with the following error: 'The timestamp must be numeric'. This issue was first reported by @joachim in #2350939-82: Implement a generic revision UI and I just encountered the same issue when working on 📌 Convert comments to be revisionable Needs work .

I can't seem to find code that set an initial value for this field (and the revision_user field for that matter) on any entity types that were already converted to be revisionable (eg. block content, terms, menu links), so I'm assuming there's existing content in the wild with NULL values for those columns.

Steps to reproduce

  1. Make an entity type revisionable
  2. Include the changes of Implement a generic revision UI Fixed in your project
  3. Visit the revision overview of a pre-existing entity

Proposed resolution

Either we should set an initial value for revision_created during the upgrade (taken from the created column), or we should handle the field being empty throughout the UI.

In 📌 Convert comments to be revisionable Needs work I created a post update hook to set the default values, but another way to do it would be to use Drupal\Core\FieldBaseFieldDefinition::setInitialValueFromField. That doesn't currently work though, but it used to before. Since the removal of SqlContentEntityStorageSchemaConverter we have to use updateFieldableEntityType when making an entity type revisionable. The installation of the revision fields happens in that method. However, setInitialValueFromField doesn't seem to work when installing fields using updateFieldableEntityType. I tried it and the revision_created and revision_log_message columns of existing comments are still NULL after the upgrade.

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Entity 

Last updated about 7 hours ago

Created by

🇧🇪Belgium dieterholvoet Brussels

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024