DER fields lead to problems when syncing database between different environments

Created on 5 October 2018, almost 6 years ago
Updated 16 August 2024, about 1 month ago

I have the following Problem when using DER fields and syncing database between two different environments

When i create a new DER field on our integration environment, aftwards sync the database from there to my local machine and try to create a new entity with a dynamic entity reference and save it i receive the following error:

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Drupal\Core\Entity\EntityStorageException</em>: SQLSTATE[HY000]: General error: 1449 The user specified as a definer (&#039;DBUSERINTEGRATION&#039;@&#039;IPINTEGRATION&#039;) does not exist: INSERT INTO {paragraph__field_teaser_dynamic} (entity_id, revision_id, bundle, delta, langcode, field_teaser_dynamic_target_id, field_teaser_dynamic_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] =&gt; 5741
    [:db_insert_placeholder_1] =&gt; 19244
    [:db_insert_placeholder_2] =&gt; teaser
    [:db_insert_placeholder_3] =&gt; 0
    [:db_insert_placeholder_4] =&gt; de
    [:db_insert_placeholder_5] =&gt; 1
    [:db_insert_placeholder_6] =&gt; commerce_product
)

The error is totally correct, since i use different db credentials for both environments.

When i dump my database on my local environment and search for the db user (DBUSERINTEGRATION) in the database dump i find the following occurences:

/*!50003 CREATE*/ /*!50017 DEFINER="DBUSERINTEGRATION"@"IPINTEGRATION"*/ /*!50003 TRIGGER paragraph__field_teaser_dynamic_der_insert BEFORE insert ON paragraph__field_teaser_dynamic FOR EACH ROW SET NEW.field_teaser_dynamic_target_id_int = IF(NEW.field_teaser_dynamic_target_id REGEXP '^[0-9]+$', CAST(NEW.field_teaser_dynamic_target_id AS UNSIGNED), NULL) */;;
/*!50003 CREATE*/ /*!50017 DEFINER="DBUSERINTEGRATION"@"IPINTEGRATION"*/ /*!50003 TRIGGER paragraph__field_teaser_dynamic_der_update BEFORE update ON paragraph__field_teaser_dynamic FOR EACH ROW SET NEW.field_teaser_dynamic_target_id_int = IF(NEW.field_teaser_dynamic_target_id REGEXP '^[0-9]+$', CAST(NEW.field_teaser_dynamic_target_id AS UNSIGNED), NULL) */;;
/*!50003 CREATE*/ /*!50017 DEFINER="DBUSERINTEGRATION"@"IPINTEGRATION"*/ /*!50003 TRIGGER paragraph_revision__field_teaser_dynamic_der_insert BEFORE insert ON paragraph_revision__field_teaser_dynamic FOR EACH ROW SET NEW.field_teaser_dynamic_target_id_int = IF(NEW.field_teaser_dynamic_target_id REGEXP '^[0-9]+$', CAST(NEW.field_teaser_dynamic_target_id AS UNSIGNED), NULL) */;;
/*!50003 CREATE*/ /*!50017 DEFINER="DBUSERINTEGRATION"@"IPINTEGRATION"*/ /*!50003 TRIGGER paragraph_revision__field_teaser_dynamic_der_update BEFORE update ON paragraph_revision__field_teaser_dynamic FOR EACH ROW SET NEW.field_teaser_dynamic_target_id_int = IF(NEW.field_teaser_dynamic_target_id REGEXP '^[0-9]+$', CAST(NEW.field_teaser_dynamic_target_id AS UNSIGNED), NULL) */;

When i check the modules code, i found the follwing function \Drupal\dynamic_entity_reference\Storage\IntColumnHandlerMySQL::createTrigger which seems to be responsible for those CREATE TRIGGER statements in the export.

My workaround for now is to
1. db sync
drush sql-sync --create-db @project.igr @self
2. dump database
drush sql-dump --result-file="dump.sql"
3. replace the definer statement in the database
sed -i ‘s/DEFINER=“DBUSERINTEGRATION"@"IPINTEGRATION"/DEFINER=“DBUSERLOCAL"@"127.0.0.1"/g’ dump.sql
4. reimport database
drush sql-drop && drush sql-cli < dump.sql

After that procedure, i can save entites with DER fields on my local machien again.

How can this be solved? Do i need a different SQL setting or something to prevent the TRIGGER statement to not write the DEFINEr of the current environment into the statement?

💬 Support request
Status

Fixed

Version

2.0

Component

Code

Created by

🇨🇭Switzerland megadesk3000

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.

  • 🇨🇦Canada paulsheldrake

    For folks that are working in a local environment you can import your DB as the root user as a work around

    MYSQL_CONNECTION_DETAILS="-h db -proot -u root default"
    zcat $DBFILE | mysql $MYSQL_CONNECTION_DETAILS
  • 🇺🇸United States coconnor

    If I explicitly designate the 3.x version in composer.json, the issue goes away.

    composer require 'drupal/dynamic_entity_reference:^3.2'

    I just experienced this issue on many of my Pantheon instances, and I was extremely concerned about how I'd rectify the issue on local/multidev/dev/test environments over the course of our project. AFAIK, the issue seems to be endemic to the 4.x version. I didn't seem to see any explicit notes re: the 4.x build hosting this issue, so I'm hoping this note helps someone.

    Hat tip to this post for pointing me in the right place.

  • 🇨🇳China lawxen

    I facing the problem of "The user specified as a definer "
    Solving ti by resaving the DER field, it seems related with https://www.drupal.org/project/dynamic_entity_reference/issues/3099176 🐛 Errors when new entity types are added (in certain cases) RTBC

  • 🇬🇧United Kingdom danharper

    Having the same issue with version 4.

    I can't test locally and I don't understand the solutions above. I'm in a position where I don't want to push any changes in case it breaks production.

    I'm dumping from platform.sh and importing into lando.

  • 🇨🇳China lawxen

    I don't understand the solutions above.

    Resaving the DER field config

Production build 0.71.5 2024