Problem/Motivation

When I tried to update the database schema of this module from 7.x-1.0 to 7.x-1.3, I met the following error.

Fatal error: Call to undefined function google_tag_assets_create() in /PATH/TO/DRUPAL/ROOT/sites/all/modules/contrib/google_tag/google_tag.install on line 251

This seems to be caused because the hook_update_N() (google_tag_update_7105()) uses the function google_tag_assets_create() which is defined in .module and the module was disabled when I tried to update the schema.

The above case can occur if one uses git to update module code and run drush updb separately.

The steps to reproduce is as below.

  1. Download google_tag-7.x-1.0.
  2. Enable google_tag.
  3. Update the code of google_tag to 7.x-1.3.
  4. Disable google_tag.
  5. Try to update the schema of google_tag to 7.x-1.3.

You can use drush to follow these steps.

drush dl google_tag-7.x-1.0
drush en google_tag
drush upc google_tag
drush dis google_tag
drush updb google_tag

Proposed resolution

Load the .module file before invoking google_tag_assets_create() in google_tag_update_7105().

Remaining tasks

  • Make patch
  • Review patch

User interface changes

(None)

API changes

(None)

Data model changes

(None)

Comments

hgoto created an issue. See original summary.

hgoto’s picture

Status: Active » Needs review
StatusFileSize
new524 bytes

I tried making a patch to address this problem.

tamas.varga’s picture

solotandem’s picture

Status: Needs review » Needs work

@hgoto Thanks for reporting this. Why does core run DB updates on a disabled module? Without looking into this further, I consider it a core 'bug' to run updates in this case. Your patch does what you intend but I will likely take a different angle.

@varga FYI your patch is out of date.

hgoto’s picture

@solotandem thanks for your response.

Why does core run DB updates on a disabled module?

I got to know Drupal relatively recently and I don't know well about the history of this behaviour. But there seems to be a variable named update_check_disabled to control the update behaviour and it seems to have been introduced in the following issue.

#162788: Include modules that aren't enabled

We can check the state of the variable at the admin update setting page (/admin/reports/updates/settings).

Check for updates of disabled and uninstalled modules and themes

Does this help for you to judge?

  • solotandem committed 6eb9e40 on 7.x-1.x
    Issue #2957648 Deprecate hook_update_7105 and 7106.
    
    Remove code but...
solotandem’s picture

Assigned: Unassigned » solotandem
Status: Needs work » Fixed

I removed the code from hook_update_7105 as the snippet files are created on enable and cron; hopefully the latter are sufficient.

Thanks for reporting this.

hgoto’s picture

@solotandem Thank you for your swift actions!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.