It has observed that, entitycache creates tables during install under hook_schema() but tables are not droped during hook_uninstall()

This causes issues when module is disabled and someone try to enable it again.

This may leads to erro like:
exception 'DatabaseSchemaObjectExistsException' with message 'Table cache_entity_file already exists.'

Comments

dineshw created an issue. See original summary.

dineshw’s picture

Status: Active » Needs work
StatusFileSize
new1.04 KB

Trying to drop existing tables in case hook_schema() gets executed again.

Better approach could be using hook_uninstall().

dineshw’s picture

Updated Patch

dineshw’s picture

Status: Needs work » Needs review

greggles’s picture

Status: Needs review » Needs work

A small code style nitpick:

+    if(db_table_exists("cache_entity_$type")){

There needs to be a space after the `if` and before the `(`.

greggles’s picture

Status: Needs work » Needs review
StatusFileSize
new891 bytes

Reroll to fix that.

Status: Needs review » Needs work
mcdruid’s picture

Hmm, as mentioned in #2 I'm not certain we want to be dropping all the existing tables every time hook_schema() is invoked.

Manually testing this patch and installing, enabling and disabling entitycache I'm still hitting errors when drupal_flush_all_caches() tries to flush tables that no longer exist.

We can keep adding workarounds (e.g. check if the table exists before adding each bin in entitycache_flush_caches()) but I think perhaps it'd be better to try a slightly different approach to solving the problem.

That may be as simple as dropping the tables in hook_uninstall(), but we'll want to check if that covers enabling/disabling too.

mcdruid’s picture

Priority: Critical » Major
Status: Needs work » Needs review
StatusFileSize
new673 bytes

Here's a patch that drops the tables in hook_uninstall().

However, this doesn't actually seem to be necessary AFAICS.

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func... says:

Database tables defined by hook_schema() will be removed automatically.

...and I've verified that works okay with some manual testing (using drush).

When the module is disabled, the tables are not removed (which I think is the correct behaviour).

I don't see any errors when the module is enabled again.

So I'm not actually able to reproduce there being any problem with letting the install/enable/disable/uninstall API work as it does now alongside the existing hook_schema() implementation.

Can anyone provide any steps to reproduce an error that requires a change in entitycache?

mcdruid’s picture

Status: Needs review » Postponed (maintainer needs more info)