SQLSTATE[HY000]: General error: 1449 The user specified as a definer does not exist

Created on 9 April 2024, 8 months ago

Problem/Motivation

Some hosting providers change the database user name on deploys or rebuilds of containers.

Preview link is using a db trigger and when this gets called SQL exception occurs:

Drupal\Core\Entity\EntityStorageException: SQLSTATE[HY000]: General error: 1449 The user specified as a definer ('9980214569b54b02ada9c0674849c3bc'@'%') does not exist: INSERT INTO "preview_link__entities" ("entity_id", "revision_id", "bundle", "delta", "langcode", "entities_target_id", "entities_target_type") 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] => 1441 [:db_insert_placeholder_1] => 1441 [:db_insert_placeholder_2] => preview_link [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => und [:db_insert_placeholder_5] => 387474 [:db_insert_placeholder_6] => node ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Drupal\Core\Database\StatementWrapperIterator->execute(Array, Array) (Line: 44)
Drupal\mysql\Driver\Database\mysql\Insert->execute() (Line: 1403)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->saveToDedicatedTables(Object, , Array) (Line: 971)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->doSaveFieldItems(Object) (Line: 718)
Drupal\Core\Entity\ContentEntityStorageBase->doSave(NULL, Object) (Line: 486)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 806)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 82)
Drupal\preview_link\PreviewLinkStorage->save(Object) (Line: 339)
Drupal\Core\Entity\EntityBase->save() (Line: 83)
Drupal\preview_link\Form\PreviewLinkForm->getEntityFromRouteMatch(Object, 'preview_link') (Line: 73)
Drupal\Core\Entity\HtmlEntityFormController->getFormObject(Object, 'preview_link.preview_link.default') (Line: 58)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 592)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 53)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

* create a preview link entity
* change db user
* try to access the preview link tab

Proposed resolution

* decouple trigger from db user

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

miiimooo Europe

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

Comments & Activities

  • Issue created by @miiimooo
  • πŸ‡ΊπŸ‡ΈUnited States kreynen

    @miiimooo thanks for linking to the DER issue. It would have taken me a long time to figure out that in 2024 a module would attempt to store username for a SQL connection in a database. The idea that database connection information never changes when most Drupal hosts now provide a dev->test->live deployment with database connection information populated in the settings.php files from environmental variables BECAUSE THEY CAN CHANGE AT ANYTIME is just a fundamentally flawed approach.

    I understand that this is only an alpha, but the steps to reproduce this error on a host like Pantheon are very simple.

    1. In the live environment, create a Preview Link with a URL like node/123/generate-preview-link
    2. Clone the live environment's database to test
    3. Attempt to access node/123/generate-preview-link

    I haven't looked into why the module is stashing the db credentials in a table and to determine if it is worth fixing that, but my solution was to simply to uninstall the module and reinstall it.

Production build 0.71.5 2024