Fatal error when editing node with auto label that's hidden with no pattern, broken pattern or unallowed pattern

Created on 3 November 2023, about 1 year ago
Updated 7 November 2023, about 1 year ago

Problem/Motivation

A fatal error can occur when nothing is entered as a pattern for the automatic label, when the pattern doesn't exist or when the pattern is rendered disallowed/unavailable through permission settings.

The website encountered an unexpected error. Please try again later.

Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null: INSERT INTO "node_field_data" ("nid", "vid", "type", "langcode", "status", "uid", "title", "created", "changed", "promote", "sticky", "default_langcode", "revision_translation_affected") 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, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => 3 [:db_insert_placeholder_2] => test [:db_insert_placeholder_3] => en [:db_insert_placeholder_4] => 1 [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => 1698991012 [:db_insert_placeholder_8] => 1698991116 [:db_insert_placeholder_9] => 1 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 1 [:db_insert_placeholder_12] => ) in Drupal\mysql\Driver\Database\mysql\ExceptionHandler->handleExecutionException() (line 43 of /var/lib/tugboat/stm/web/core/modules/mysql/src/Driver/Database/mysql/ExceptionHandler.php).

Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null: INSERT INTO "node_field_data" ("nid", "vid", "type", "langcode", "status", "uid", "title", "created", "changed", "promote", "sticky", "default_langcode", "revision_translation_affected") 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, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => 3 [:db_insert_placeholder_2] => test [:db_insert_placeholder_3] => en [:db_insert_placeholder_4] => 1 [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => 1698991012 [:db_insert_placeholder_8] => 1698991116 [:db_insert_placeholder_9] => 1 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 1 [:db_insert_placeholder_12] => ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of /var/lib/tugboat/stm/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Steps to reproduce

1. Install Drupal 10 with auto_entitylabel enabled.
2. Set Automatic label to "Automatically generate the label and hide the label field" or "Automatically generate the label if the label field is left empty" with nothing entered for pattern. Alternatively enter a pattern that doesn't exist, e.g. [node:field_test]
3. Create a Test type node.
4. Edit the node, save and observe the fatal error:
"The website encountered an unexpected error. Please try again later."

I originally encountered this error through a permissions-based edge case:
1. Install Drupal 10 with contrib modules auto_entitylabel, token, field_permissions enabled.
2. Create Test content type with field_test plaintext field.
3. Set custom field permissions for field_test to have nothing checked except for admin options and anonymous user "View anyone's value for field field_test."
4. Set Automatic label to "Automatically generate the label and hide the label field" with pattern [node:field_test]
5. Create a Test type node and enter text in field_test, which will populate the node title.
6. Create a test user with no roles.
7. Set role permissions to allow authenticated users to edit their own Test content type content.
8. Set the recently created node's author to the test user.
9. Log in as the test user, edit the node and observe the fatal error.

Another example would be using a content type's field as the pattern, then later deleting the field. Going to edit a node of that type before updating the automatic label pattern renders the fatal whitescreen error.

Proposed resolution

For my original edge case that cropped up on a site, a simple way around it is to enable "View anyone's value for field field_test" for authenticated users on the field_test field permissions.

But the fatal error can occur more generically as described above.

🐛 Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

🇺🇸United States j_s

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

Comments & Activities

  • Issue created by @j_s
  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 7.3 & MySQL 8
    last update about 1 year ago
    Composer error. Unable to continue.
  • @viren18febs opened merge request.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India viren18febS

    HI @joshuasosa

    I have fixed the issue & added MR, please review.

  • 🇺🇸United States j_s

    The patch with MR!16 resolves the issue if nothing is entered in the pattern field. But it continues to generate a fatal error if a non-existent pattern or pattern using a disallowed field is used.

    If a pattern is entered, maybe there should be some sort of check to verify/validate the pattern on label generation.

Production build 0.71.5 2024