- 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.
- In the live environment, create a Preview Link with a URL like node/123/generate-preview-link
- Clone the live environment's database to test
- 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.
- πΊπΈUnited States damienmckenna NH, USA
Just hit this problem on a site after some recent codebase updates. FWIW the site is hosted at Pantheon the Preview Link configuration was not changed recently.
- πΊπΈUnited States damienmckenna NH, USA
The problem isn't limited to 2.2.0-alpha1, I tested all 2.1.0 and 2.2.0 alpha releases and they all have the error.
- πΊπΈUnited States damienmckenna NH, USA
I wonder if this is a problem from Dynamic Entity Reference?
- πΊπΈUnited States damienmckenna NH, USA
The recommendation in the DER module is to resave the field, but that's a little harder to do with Preview Link because the field was created programmatically, rather than within the UI.
- πΊπΈUnited States damienmckenna NH, USA
I think it would be useful to have a Drush command to resave the fields, to work around these problems.
- πΊπΈUnited States damienmckenna NH, USA
I tried this:
$field_specs = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('preview_link'); if (!empty($field_specs['entities'])) { \Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition($field_specs['entities']); }
That seems to resolve the problem.
- πΊπΈUnited States damienmckenna NH, USA
BTW before I updated the field specs I had to truncate the tables:
$db = \Drupal::database(); $db->query("TRUNCATE {preview_link}")->execute(); $db->query("TRUNCATE {preview_link__entities}")->execute();
- πΊπΈUnited States jmcgehee
@damienmckenna, I'm new to this issue. How did you run this code fix?
- πΊπΈUnited States damienmckenna NH, USA
I added them to a hook_update_NAME() script in a custom module.