When date is installed using the setup function in simpletest, the .install code in the following module throws exceptions. Doing the following causes the install code in 'cck_date_test' to throw exceptions:
// Install date.
function setUp() {
parent::setUp('content', 'text', 'date_api', 'date_timezone', 'date', 'cck_date_test');
}
However, just removing date, eliminates the exceptions and test code run prefectly:
// Don't install date.
function setUp() {
parent::setUp('content', 'text', 'date_api', 'date_timezone', 'cck_date_test');
}
Strangely, if the code in the .install file is removed and placed in a test, no exceptions are thrown.
Attached is a small module I wrote just to demonstrate this problem.
Comments
Comment #1
b508 commentedPHP Version 5.2.6
Comment #2
b508 commentedComment #3
webchickFWIW, here are the exceptions I'm getting when I try and run this:
I get the views one on each test in the group.
Comment #4
webchickThe stack trace for this looks something like this:
1. SimpleTest enables the following modules in sequence:
- content
- text
- date api
- date timezone
- date
- cck_date_test (custom module which programmatically creates a node type with a text field)
If we remove the date stuff and sub in something like number, things work fine. So it's something that one of the date-related modules is doing on install (or that's our current theory).
2. When cck_date_test_install() calls http://api.lullabot.com/content_field_instance_create (which then calls http://api.lullabot.com/content_field_instance_expand), things start to break down because
$widget_types = _content_widget_types();(http://api.lullabot.com/_content_widget_types) is returning an empty array. Since the code here obviously expects this to never happen, exceptions start flying fast and furious.3. The only thing "special" about date module vs. other content types is that it's doing a call to date_install_clear(); at the end of its various hook_install() / hook_enable() / hook_uninstall(), etc. calls. Unfortunately, cvs annotate doesn't provide much of a clue as to why this was done. :(
4. And unfortunately, even when commenting out those calls, the issue still occurs. :( So we're left to wonder if it's not something deeper in the system somewhere (CCK, Date API, or SimpleTest?) that's causing the issue.
I know that's not a lot to go on, but any ideas? :\
Comment #5
boombatower commentedThe patch at http://drupal.org/node/360925#comment-1627568 fixes one the table related "User warning" on all test.
Comment #6
boombatower commentedPlacing
in
cck_date_test_install()reveals that cck does not have any widget types as the errors seem to show.Comment #7
boombatower commentedPart of the problem seems to be that the module_list() is incomplete.
And interestingly every time
module_list(TRUE);is called another set of exceptions is generated:Comment #8
boombatower commentedAfter adding a ton of debug statements I think I discovered where the issue is. It is more rudimentary then originally thought.
The module_list() only contains the full list after
drupal_install_modules()has completed.cck_date_test_install()is called during its execution and does not have the full module list and therefore cck doesn't know about any widgets.This seems like it could be solved by installing core modules then additional modules. I will try that.
Comment #9
boombatower commentedYep, that fixed !!!
Patch coming need to clean this up. Seems like we should fix this in core and then backport, patch should apply easily for those waiting on it.
Comment #10
boombatower commentedI believe this is the holy grail of SimpleTest bugs. Already a number of issues were marked duplicates of this one and I have seen plenty of others. This bug fits the description needed to causes a wide variety of bugs.
I have tested this on SimpleTest 6.x-2.x with the test described above and it works properly. Lets hope D7 is happy with it. :)
Comment #11
boombatower commentedThis also fixes the bug at #440824: Reset module_list() and module_implements() on test setup.. (or at least in my case)
Comment #12
webchickAwesome work, Jimmy! :D
Is this something we can write a test case for? DAMN that was annoying to debug...
Comment #13
boombatower commentedShould be able to make a test module that calls a hook or something else that requires the module list to be intact during install time. I'll get to this a bit later.
Comment #14
boombatower commentedD6 patch, for testing.
Comment #16
boombatower commentedHmm, I thought D6 was the keyword. I'll have to check that
Comment #17
yched commentedSubscribe. This patch is effectively fixing some nasty test failures we were having in #372743: Body and teaser as fields.
Comment #18
lyricnz commentedboombatower: the patch in #14 fixes the issue for me
Comment #19
David_Rothstein commentedSubscribe. Since the bug appears to be within
drupal_install_modules()itself, then for D7 maybe it would be better to fix it there?For a second I also thought this might be a symptom of #222109: module_list() should be rewritten as 2 functions: module_list() and module_list_bootstrap() but I think it is separate...
Comment #20
boombatower commentedI would be fine with a fix in drupal_install_modules for D7, and the patch for D6. Although technically this is a bug in D6 as well and thus it could be backported.
Comment #21
damien tournoud commentedIndeed, the bug has nothing to do with Simpletest. On my installation profiles, I have to do ugly stuff like:
We need to rebuild the registry and the module cache between each installation, in
_drupal_install_module().Comment #22
boombatower commentedAppears to only be issue in D6 after some tinkering. I'll post further details shortly.
EDIT: I believe I know why.
Comment #23
boombatower commentedI have included patches for Drupal 6 & 7 that add tests that perform the exact same check. The one for D6 fails and the one for D7 passes. If you apply the D6 patch to SimpleTest the D6 test also passes. The tests check that the hook_menu() is available for a different module.
I believe this is due to the registry in D7, as in D6 the only file loaded during install is the .install file and in D7 the registry will auto load hooks which is the entire issue behind this. The module list and hook implementations is out of date and thus CCK and other modules do not work properly at install time.
I have placed
module_list(TRUE, FALSE)andmodule_implements('', FALSE, TRUE)in a number of places as well as inside_drupal_install_modulewithout success. It has to be related to either the order of module installation (if it gets out of order) or something else that occurs during thedrupal_install_modules()chain since my D6 patch forces SimpleTest to non-install core modules one at a time and it works.Still working on this.
Comment #24
boombatower commentedBy changing:
to:
it works. Basically the same thing the SimpleTest patch was doing. I was trying more things in _drupal_install_module(), but it appears to want them together which makes sense, as hooks cannot be called until the module is enabled. This seems like a logic flaw which still exists in core, but seems like it is being hidden by the registry.
I am not sure this is a true solution, but it demonstrates the issue and a fix as the tests pass with patch and without SimpleTest patch.
Comment #25
chx commentedSorry, my fault, i dropped the ball after graph.inc got in, modules should be batched really, and if i remember correctly then graph.inc gives you a pretty numbering of which modules goes in which batch,
Comment #26
yched commentedBatching modules will account for explicit dependencies, right ? But what if module foo does
if module_exists('bar')in its install process without an explicit dependency ('progressive enhancement') ?OTOH, rebuilding the registry after each module install raises the chance of timeout...
Comment #27
dries commentedThis patch might be holding up #372743: Body and teaser as fields which is a big patch. Bumping this to critical for prioritization purposes.
Comment #28
bjaspan commentedsubscribe
Comment #29
boombatower commentedI am not sure exactly what chx is suggesting in #25 so I need further clarification or someone to write the patch.
Comment #30
yched commentedI *think* chx meant using graph.inc to sort out dependencies and determine sets of independent modules that can be installed together :
I'm still wondering about my comment in #26, though.
Also, not tightly related, but it might belong to the same design topic (or not - I'm not familiar enough with these areas), and is also a blocker for 'Body as field' : #479200: missing node_rebuild_types() in setUp()
Comment #31
boombatower commentedPerhaps we should commit the patch in #24 or the SimpleTest patch and leave the issue open for a cleaner fix since there seems to be a number of issues blocked by this.
Comment #32
boombatower commentedAppears to be another instance of this bug: http://drewish.com/node/134.
Comment #33
yched commentedNote that the patch in #6 got committed to D7 along with #372743: Body and teaser as fields, which was subject to massive reroll hell, so waiting for The Right Fix to be figured out here was getting harder and harder.
From comment #188 over there:
"If the fixes are deemed less-than-perfect, they can be polished later on by the competent and interested parties, which currently do not seem to care too much (also because the bug can only be reproduced by patching HEAD right now). If needed, the 'right' fix will be easier to fine-tune with the BAF patch in, since any 'wrong' fix will simply cause test failures."
Attached is the exact code that got committed - note the additional
node_type_clear();(explained in the same #188 comment in the Body as Field thread)back to CNW, if people want to advocate for a better fix.
Comment #34
boombatower commentedSo it is clear this is a problem in core...what method do we want to take to solve this...seems like we should make a change to the drupal core install system...but which way.
As I've said before...given an excepted method of attack I am ready and willing to work on this.
Comment #35
dpearcefl commentedHas this been fixed in the latest D6?
Comment #36
dpearcefl commented