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!

CommentFileSizeAuthor
#1 token-drush-updb-2387889-1.patch1.1 KBdsnopek

Comments

dsnopek’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.1 KB

Here 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.

dsnopek’s picture

Category: Task » Bug report

Er, and it's a bug report.

dave reid’s picture

This is a duplicate of a bug in Drush: https://github.com/drush-ops/drush/pull/399. Make sure to use a more recent version.

dsnopek’s picture

Blergh! 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.

dave reid’s picture

A good workaround is to call module_implements('', FALSE, TRUE); at the beginning of your update hook and then it will work.

Status: Closed (duplicate) » Needs review
dave reid’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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