Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drush update-db returns exit code 0 on failure #3094

Closed
pfrenssen opened this issue Oct 23, 2017 · 6 comments
Closed

drush update-db returns exit code 0 on failure #3094

pfrenssen opened this issue Oct 23, 2017 · 6 comments
Labels

Comments

@pfrenssen
Copy link
Member

When I am executing database updates and one of the updates fails, then the batch process is aborted, but the cache is still rebuilt and the command returns a success message and exit code 0.

$ ./vendor/bin/drush updb
 ---------------- ---------------- ------------- --------------------------------------------- 
  Module           Update ID        Type          Description                                  
 ---------------- ---------------- ------------- --------------------------------------------- 
  joinup_migrate   add_user_73932   post-update   Add the missed 'simatosc' user (uid 73932).  
  joinup_migrate   disable_update   post-update   Disable the Update module.                   
  joinup_migrate   more_redirects   post-update   Add more specific redirects.                 
 ---------------- ---------------- ------------- --------------------------------------------- 

 Do you wish to run the specified pending updates? (yes/no) [yes]:
 > yes

 [error]  Drupal\Core\Database\DatabaseNotFoundException: SQLSTATE[HY000] [1049] Unknown database 'db_name' in Drupal\Core\Database\Driver\mysql\Connection::open() (line 153 of core/lib/Drupal/Core/Database/Driver/mysql/Connection.php). 
 [ok] Post updating joinup_migrate
 [success] Cache rebuild complete.
 [success] Finished performing updates.
$ echo $?
0
@weitzman
Copy link
Member

Thanks for the quick testing. I may have been a bit over-aggresive with my most recent refactor. If you have time to debug it further, I'd be appreciative. Otherwise, I'll investigate soon.

@claudiu-cristea
Copy link
Member

Let's work here #3095. Unfortunately I uncovered also another bug that makes the batch process ongoing and repeating the same updates until it reaches timeout

@pfrenssen
Copy link
Member Author

I had looked at it yesterday and the error message is present deep in the batch process code. It gets passed in $proc['output'] in _drush_backend_invoke() but I don't know how to bubble up that error all the way to the top. The output gets parsed by drush_backend_parse_output(), maybe we should loop over the content and call drush_set_error() if there is an error message in the content?

The recent refactor did not cause this regression by the way, it also happens in 9.0.0-beta7 before the refactor.

@weitzman
Copy link
Member

I wonder if we could work on the lines below. basically, there was an error if $data['error_status] = 1. That would replace the check for drush_get_error() and $data['context'] (I think).

Hopefully thats enough to get someone started.

drush/includes/batch.inc

Lines 141 to 145 in fc39fc4

while (!$finished) {
$data = drush_invoke_process('@self', $command, $args);
$finished = drush_get_error() || !$data || (isset($data['context']['drush_batch_process_finished']) && $data['context']['drush_batch_process_finished'] == TRUE);
}

@gaelg
Copy link
Contributor

gaelg commented Nov 9, 2017

Edit: I first put another example, but it's another bug: #3127

@jonhattan
Copy link
Member

It is confusing because involves several levels of nesting.

First, updatedb sets a batch in UpdateDBCommands::updateBatch() and delegate processing to drush_backend_batch_process(); that spawns a new process.
The batch operations callback and the finish callback are UpdateDBCommands::updateDoOne(), and ::updateFinish respectively. It would be clear to move the batch callbacks to a separate class.

The batch process itself is succesful, this is why error_status is 0 and it's ok. What we want is to capture the batch results and identify what means a failure in the context of updatedb command. See #3188

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants