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.
- Download google_tag-7.x-1.0.
- Enable google_tag.
- Update the code of google_tag to 7.x-1.3.
- Disable google_tag.
- 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)
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | google_tag-fix_error_on_update-1.13-2957648-3.patch | 596 bytes | tamas.varga |
| #2 | google_tag-fix_error_on_update-2957648-2.patch | 524 bytes | hgoto |
Comments
Comment #2
hgoto commentedI tried making a patch to address this problem.
Comment #3
tamas.varga commentedComment #4
solotandem commented@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.
Comment #5
hgoto commented@solotandem thanks for your response.
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_disabledto 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).
Does this help for you to judge?
Comment #7
solotandem commentedI 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.
Comment #8
hgoto commented@solotandem Thank you for your swift actions!