Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently, hook_install is invoked before the schema version is recorded for a newly installed module. If hook_install fails for some reason, the modules schema version is still SCHEMA_UNINSTALLED, which then prevents the module from actually being uninstalled.
The fix is pretty simple.
Comment | File | Size | Author |
---|---|---|---|
#4 | broken_test.patch | 3.73 KB | matt2000 |
schema_before_install.patch | 1.07 KB | matt2000 | |
Comments
Comment #1
matt2000 CreditAttribution: matt2000 commented...i.e, we're just putting all the schema stuff together, without giving hook_install a chance to interrupt what should be a connected process.
Comment #2
matt2000 CreditAttribution: matt2000 commentedTests can be provided for this only after #793660: Check for failure of hook_install
Comment #3
chx CreditAttribution: chx commentedThe linked issue really causes me to frown. We need a consistent strategy for exceptions and so on -- this issue should not be held up by that.
Comment #4
matt2000 CreditAttribution: matt2000 commentedHere's a test that should fail if we have #793660: Check for failure of hook_install but not this, and should pass if we have both.
Comment #5
matt2000 CreditAttribution: matt2000 commentedDidn't mean to reset chx. To be clear, only the patch at the top is RTBC. Patch in #4 is purely academic at this point.
Comment #7
matt2000 CreditAttribution: matt2000 commentedwell yeah, I said it would.
Comment #8
Dries CreditAttribution: Dries commentedThis is a hack, but probably OK given that the current situation is broken too. I studied the surrounding code for a bit, and it looks OK -- a better fix will require some work so I committed this to CVS HEAD, but I'm marking this 'needs work', especially given that we have the beginnings of a test in this issue.
Comment #9
David_Rothstein CreditAttribution: David_Rothstein commentedYeah, I see what this is trying to solve, but it does not really seem quite correct... Why would we mark something as installed that hasn't actually been installed yet? And if hook_install() fails, do we really expect that hook_uninstall() will do any better? - or that the user will even figure out what's going on enough to run it?
Seems like the correct fix would be more along the lines of moving this code back where it was, but also putting it in a try-catch block; then if an exception is caught, running drupal_uninstall_schema() immediately so as to restore things as close to the original state as possible. I am not sure if that should happen in this issue or the other one.
Comment #10
matt2000 CreditAttribution: matt2000 commentedThe correct question is, what exactly has been installed, and what hasn't? We DID install the schema, and so we mark it as installed; we might fail at some other kind of set-up which may or may not be properly termed 'installation', but that's a separate questions. (And a separate issue, as of right now.)
Putting schema install and module install in the same try{} block is not a good idea, IMHO. Putting them both in their own try{} blocks is probably useful, but may not be the best approach. As chx pointed out, try{} protects us only from exceptions, not from other kinds of fatal errors.