During hook_update_N() functions, when run from drush updb, field tokens always evaluate to empty string.
You can reproduce this by having a pathauto pattern setup for node content which includes a field token (like: [node:field_category] where that is a taxonomy reference field) and then writing a hook_update_N() function which loads and saves an existing node. You'll see that the field token part of the path disappears!
I've traced this down to module_implements() and order that it's loading .inc files and checking for hook implementations. Basically, it's looping through the list of modules (in name and weight order), attempting to load $module.tokens.inc and then checking if the hook exists. It does "field" before "token", however, field_tokens() is implemented in token.tokens.inc, which won't be loaded yet!
See the implementation on api.drupal.org for more information: https://api.drupal.org/api/drupal/includes%21module.inc/function/module_...
This happens when running the update functions via drush, because drush clears the cache for module_implements() and then works from the static cache for the rest of the time. I'm using Drush 6.2.0.
I'll upload a patch in a few minutes to fix this!
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | token-drush-updb-2387889-1.patch | 1.1 KB | dsnopek |
Comments
Comment #1
dsnopekHere is a simple patch that fixes this issue in my testing. However, this problem probably affects any of the other hook functions that happen alphabetically before token, for example,
profile_tokens(). But I don't have an environment setup to test if that's the case or not.Comment #2
dsnopekEr, and it's a bug report.
Comment #3
dave reidThis is a duplicate of a bug in Drush: https://github.com/drush-ops/drush/pull/399. Make sure to use a more recent version.
Comment #4
dave reidAlso related: #534594: [meta] system info cache writing and registry rebuilding is broken without a full bootstrap and #496170: module_implements() cache can be polluted by module_invoke_all() being called (in)directly prior to full bootstrap completion
Comment #5
dsnopekBlergh! Thanks, Dave. Running locally with drush 6.5 works correctly without my patch. Unfortunately, running on Pantheon doesn't work - I presume it's because they have an older drush installed, but we'll figure something else out for that.
Comment #6
dave reidA good workaround is to call
module_implements('', FALSE, TRUE);at the beginning of your update hook and then it will work.Comment #8
dave reid