programmatically saving an entity with only a default datetime_range start throws Integrity constraint violation

Created on 15 March 2023, almost 2 years ago
Updated 16 March 2023, almost 2 years ago

Problem/Motivation

When saving an entity programmatically that has a datetime_range with a default start date, a SQL error is thrown if the end date is not provided. Does not matter if the field is required or not.

Any other empty field (even a required text field) does not throw this error, so it does not seem like a blank field should throw an error on being saved programmatically.

Steps to reproduce

1. Install D9
2. Add a datetime_range field to basic page, add a start default of "Now" and end default of "Blank"
3. Programmatically create a new basic page:

$node = \Drupal::entityTypeManager()->getStorage('node')->create([
'title' => 'test',
'type' => 'page',
]);
$node->save();

Results in:

Error message
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'field_daterange_end_value' cannot be null: INSERT INTO "drupal_node__field_daterange" ("entity_id", "revision_id", "bundle", "delta", "langcode", "field_daterange_value", "field_daterange_end_value") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => 8 [:db_insert_placeholder_1] => 8 [:db_insert_placeholder_2] => page [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => en [:db_insert_placeholder_5] => 2023-03-15T21:28:27 [:db_insert_placeholder_6] => )

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

9.5

Component
DatetimeΒ  β†’

Last updated 6 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States djdevin Philadelphia

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

Comments & Activities

Production build 0.71.5 2024