Problem/Motivation

getting

$ drush pmu contact_storage
The following extensions will be uninstalled: contact_storage
Do you really want to continue? (y/n): y
PDOException: SQLSTATE[HY000]: General error: 1 no such column: id in /srv/core/lib/Drupal/Core/Database/Driver/sqlite/Statement.php:82                                                               [error]
Stack trace:
#0 /srv/core/lib/Drupal/Core/Database/Driver/sqlite/Statement.php(82): PDO->prepare('SELECT 1 AS exp...')
#1 /srv/core/lib/Drupal/Core/Database/StatementPrefetch.php(158): Drupal\Core\Database\Driver\sqlite\Statement->getStatement('SELECT 1 AS exp...', Array)
#2 /srv/core/lib/Drupal/Core/Database/Driver/sqlite/Statement.php(90): Drupal\Core\Database\StatementPrefetch->execute(Array, Array)
#3 /srv/core/lib/Drupal/Core/Database/Connection.php(631): Drupal\Core\Database\Driver\sqlite\Statement->execute(Array, Array)
#4 /srv/core/lib/Drupal/Core/Database/Query/Select.php(510): Drupal\Core\Database\Connection->query('SELECT 1 AS exp...', Array, Array)
#5 /srv/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(1792): Drupal\Core\Database\Query\Select->execute()
#6 /srv/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php(637): Drupal\Core\Entity\Sql\SqlContentEntityStorage->countFieldData(Object(Drupal\Core\Field\BaseFieldDefinition),
true)
#7 /srv/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(1577):
Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->onFieldStorageDefinitionDelete(Object(Drupal\Core\Field\BaseFieldDefinition))
#8 /srv/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(1593): Drupal\Core\Entity\Sql\SqlContentEntityStorage->Drupal\Core\Entity\Sql\{closure}()
#9 /srv/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(1578): Drupal\Core\Entity\Sql\SqlContentEntityStorage->wrapSchemaException(Object(Closure))
#10 /srv/core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php(172):
Drupal\Core\Entity\Sql\SqlContentEntityStorage->onFieldStorageDefinitionDelete(Object(Drupal\Core\Field\BaseFieldDefinition))
#11 /srv/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php(271):
Drupal\Core\Field\FieldStorageDefinitionListener->onFieldStorageDefinitionDelete(Object(Drupal\Core\Field\BaseFieldDefinition))
#12 /srv/core/lib/Drupal/Core/Extension/ModuleInstaller.php(432): Drupal\Core\Entity\EntityDefinitionUpdateManager->uninstallFieldStorageDefinition(Object(Drupal\Core\Field\BaseFieldDefinition))
#13 /srv/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(91): Drupal\Core\Extension\ModuleInstaller->uninstall(Array, true)
#14 phar:///usr/bin/drush/commands/core/drupal/environment.inc(227): Drupal\Core\ProxyClass\Extension\ModuleInstaller->uninstall(Array)
#15 phar:///usr/bin/drush/commands/core/drupal/pm_8.inc(79): drush_module_uninstall(Array)
#16 phar:///usr/bin/drush/commands/pm/pm.drush.inc(1250): _drush_pm_uninstall(Array)
#17 phar:///usr/bin/drush/includes/command.inc(422): drush_pm_uninstall('contact_storage')
#18 phar:///usr/bin/drush/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
#19 phar:///usr/bin/drush/includes/command.inc(199): drush_command('contact_storage')
#20 phar:///usr/bin/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
#21 phar:///usr/bin/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#22 phar:///usr/bin/drush/includes/startup.inc(465): drush_main()
#23 phar:///usr/bin/drush/includes/startup.inc(369): drush_run_main(false, '/', 'Phar detected. ...')
#24 phar:///usr/bin/drush/drush(114): drush_startup(Array)
#25 /usr/bin/drush(10): require('phar:///usr/bin...')
#26 {main}

Next Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY000]: General error: 1 no such column: id: SELECT 1 AS expression
FROM
{contact_message} t
WHERE id IS NOT NULL
LIMIT 1 OFFSET 0; Array
(
)
 in /srv/core/lib/Drupal/Core/Database/Connection.php:692
Stack trace:

Proposed resolution

Implement proper contact_storage_uninstall() hook

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

andypost created an issue. See original summary.

andypost’s picture

Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new829 bytes

Guess contact_form (config entity) will server update themself

andypost’s picture

After module uninstalled it's fields and message table still live and never purged

$ drush sqlq .tables|grep contact_message
contact_message                  
/srv $ drush sqlq 'select * from field_deleted_data_3fbcba1c35'
feedback|1|1|1|en|0|1
andypost’s picture

After uninstall/install/uninstall table and field tables remains unchanged but empty


$ drush pmu contact_storage
The following extensions will be uninstalled: contact_storage
Do you really want to continue? (y/n): y
contact_storage was successfully uninstalled.                                                                                                                                                            [ok]
/srv $ drush sqlq 'select * from contact_message__field_bool'

/srv $ drush sqlq 'select * from contact_message'

andypost’s picture

andypost’s picture

StatusFileSize
new694 bytes
new1.49 KB

The last submitted patch, 6: 3039906-15-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 6: 3039906-15.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

vacho’s picture

Message that appear when you try uninstall the module by GUI:

Drupal\Core\Entity\EntityStorageException: Exception thrown while performing a schema update. SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entity_table.id' in 'field list': INSERT INTO {field_deleted_data_38d3088921} (bundle, entity_id, revision_id, langcode, created_value, deleted, delta) SELECT entity_table.contact_form AS bundle, entity_table.id AS entity_id, entity_table.id AS revision_id, entity_table.langcode AS langcode, entity_table.created AS created_value, :deleted AS deleted, :delta AS delta FROM {contact_message} entity_table WHERE entity_table.created IS NOT NULL FOR UPDATE; Array ( [:deleted] => 1 [:delta] => 0 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->wrapSchemaException() (line 1490 of /var/www/html/contribdrupal86/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

When the patch #15 is applied
By GUI:
Then this message doesn't appear and module is well uninstalled.

By Drush command:
#drush pmu contact_storage
Then this message doesn't appear and module is well uninstalled.

In both cases tables: contact_message, contact_message__field_* Are empty

Environment: Drupal 8.6.11, Drush 8, mysql 5.

andypost’s picture

Status: Needs work » Needs review
Parent issue: » #3018997: Plan for next Contact Storage release
andypost’s picture

vacho’s picture

The patch works fine in all cases that I review except when the contact form have an "Options email" field. It is the reason why the test fail too.
I trace the bug to the core and report it. https://www.drupal.org/project/drupal/issues/3040031

pandaski’s picture

#6

typo in patch

\Drupal::service('module_installer')->istall(['contact_storage']);

to

\Drupal::service('module_installer')->install(['contact_storage']);
pandaski’s picture

Status: Needs review » Needs work
andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new644 bytes
new695 bytes
new1.49 KB

The last submitted patch, 15: 3039906-15_test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 15: 3039906-15_fix.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

eelkeblok’s picture

Note that #3028830: SQL error when uninstalling is trying to solve the same issue, I closed it as a duplicate, although I now realize the solution here is also a bit "hacky", with uninstalling and installing storage. Doesn't it mean there is an underlying issue, when Drupal is unable to cleanly uninstall the entity?

mlzr’s picture

#15 works.
First I want to uninstall toe 'Contact Storage' module, and it won't uninstall. Even, the page /admin/modules/uninstall gives a WSOD.
After apply the patch the uninstall works fine.

thanks,
MZLR

vasiliyrepin’s picture

StatusFileSize
new14.32 KB
new23.74 KB

#15 works.
But after uninstall and install (reinstall) some elements of this module disappears.
1. At admin/structure/contact disappears View Messages at Website feedback
2. At /admin/structure/contact/messages incorrect view list data.
bug
bug2

gilbertdelyon’s picture

StatusFileSize
new36.4 KB

Same issue here.
D 9.3.15
PHP 8.0.19

Some months ago, Install Contact Storage for testing .
Today, I cannot uninstall properly .
Go to Admin > Modules > Uninstall : error (so, I cannot uninstall any other module)

What I did:
- Delete module folder
- Empty all cache tables in database
- And site works again!

Then:
- Reinstall contact storage. It works.
- send contact message
- go to admin > structure > Contact Forms > List
Incorrect view

file
Then:
Install contact storage in a fresh D 9.3.15 site without any other contrib or custom module. It Seems to work properly.
Could we have a incompatibility issue with another module or setting ?

Contact storage has not been updated since June 2020 (2 years ago). Not very promissing.

berdir’s picture

Issue tags: -Needs tests

The referenced core issue was closed. This will need a step, either manual or automated to first delete all configurable fields, as shown in the test fail, before deleting the entity type itself. The simplenews module has a manual form that does that,.

silverham’s picture

Rerolled against latest release 8.x-1.3.

ultimike’s picture

The patch in 23 works for me as well.

-mike

roybrockington’s picture

#23 for the win on Drupal 9.5.9, at last!

chike’s picture

#23 is working for me on Drupal 10.2.0.

liliplanet’s picture

Hi! Had contact storage with fields installed.

Uninstalled contact_storage, now get error: The following table(s) do not have a primary key: contact_message.

Patched as per #23, installed, un-installed, error is still there.

I removed all contact_message fields from my database, error is gone, hope it does not cause issues down the line.

johnpicozzi’s picture

Looks like the patch in #23 doesn't apply cleanly to 8.x-1.5