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
Comment #1
sreynen commentedAre 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().
Comment #2
David_Rothstein commentedFrom 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():
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.)
Comment #3
catchComment #4
bjaspan commentedIn 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.
Comment #5
plopescHello,
I experienced this same issue creating languages that does not appear after in
locale_language_list()function, because it callslanguage_list(), which usesdrupal_static().I created the language through the following code:
After rewriting the test and check the code, I found that the bug was related to
drupal_static(), and it would be fixed callingdrupal_static_reset()from my test code before callinglocale_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