Steps to reproduce:

1. Call taxonomy_get_tree($vid).
2. Create a term in $vid.
3. Call taxonomy_get_tree($vid) again. Notice your new term is not included.

The taxonomy.module does not maintain its static caches correctly to ensure its API works consistently. See http://drupal.org/node/826028#comment-3189008 for a patch that has to call drupal_static_reset() to work around this. I notice other taxonomy tests do the same.

Are we accepting this behavior in D7? Eliminating it is the whole reason drupal_static() was created.

Comments

sreynen’s picture

Are you creating the term in step 2 with taxonomy_term_save()? I just went through this process and taxonomy_term_save() reset the static variables as expected by calling taxonomy_terms_static_reset().

David_Rothstein’s picture

From the linked-to code, it looks like the term is being created in the test via this code, which happens between the two calls to taxonomy_get_tree():

    // Insert the terms in a comma separated list. Vocabulary 1 is a
    // free-tagging field created by the default profile.
    $edit[$instance['field_name'] . "[$langcode]"] = implode(', ', $terms);
    $this->drupalPost('node/add/page', $edit, t('Save'));

If so, then this isn't a taxonomy module bug, but rather a Simpletest issue; the saving happens in a different thread from where the test is being run and therefore doesn't have an opportunity to clear the appropriate static caches.

Not sure if there is already an issue for this, but seems like we should have Simpletest always call a complete drupal_static_reset() from inside drupalPost()? (Because once drupalPost goes off and does the POST via its own separate HTTP request, etc, I don't think we have any good way to know which static caches might have been invalidated by that.)

catch’s picture

Title: taxonomy.module has static caching bugs » Simpletest has static caching bugs
Component: taxonomy.module » simpletest.module
bjaspan’s picture

Priority: Critical » Normal

In that case I no longer advocate for this being critical. It's not as big a problem for test authors to have to clear static caches as it is for normal API users. Still a bug, of course.

plopesc’s picture

Hello,

I experienced this same issue creating languages that does not appear after in locale_language_list() function, because it calls language_list(), which uses drupal_static().

I created the language through the following code:

  // Add a new language.
  $edit = array(
    'langcode' => 'es',
  );
  $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));

After rewriting the test and check the code, I found that the bug was related to drupal_static(), and it would be fixed calling drupal_static_reset() from my test code before calling locale_language_list().

Ill try to work on this issue, but would be helpful if somebody could point me now about how to start it.

Regards

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.