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.
Problem/Motivation
If you see the first lines of the Schema::dropTable() method you will see that if there is not table no exception is thrown.
if (!$this->tableExists($table)) {
return FALSE;
}
Proposed resolution
Throw an exception like in the Schema::addField() method
if (!$this->tableExists($table)) {
throw new SchemaObjectDoesNotExistException(t("Cannot add field @table.@field: table doesn't exist.", ['@field' => $field, '@table' => $table]));
}
But with the correct message.
Remaining tasks
Test the patch.
User interface changes
None.
API changes
Update the doc with the throw exception info.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#8 | throw_an_exception_if_the_table_doesnt_exist_in_schema_droptable-2862340-8.patch | 2.81 KB | adriancid |
Comments
Comment #2
adriancidComment #4
daffie CreditAttribution: daffie commentedI like this change. All other methods in Drupal\Core\Database\Schema that test if the table exists will throw the exception: SchemaObjectDoesNotExistException. The only exception is the method dropTable(). The problem is that such a change will be bc-break and that will be only allowed in a new major version of Drupal (Drupal 9.0). For more information see https://www.drupal.org/core/d8-allowed-changes.
Comment #5
adriancid@daffie why do you think that this will be bc-break? I come from read the link and this is the definition:
Maybe I can't get the point, can you help me to understand please?
Comment #6
adriancidComment #7
daffie CreditAttribution: daffie commentedIf someone runs this code in his/her contrib module and they try to delete a table that does not exists the dropTable() method would return FALSE. The rest of their code will still run. If we make the change that you are suggesting the dropTable() method will throw an exception and if uncaught will stop the running of the code. This is a major change and not allowed.
Comment #8
adriancidUpdated the message according to the others exception messages.
Comment #9
adriancidComment #11
xjmComment #12
daffie CreditAttribution: daffie commentedComment #13
xjmSee also #2862667-22: Throw an exception if the field doesn't exist in Schema::dropField() comments 22 and 23; we need to find a BC way to do this in the continuous upgrade path, because calling code could be correctly handling the scenario where the return value is
FALSE
.Comment #14
xjmAlso, the exception messages should not be translated.