Problem/Motivation

In #2996436: Follow-up to fix DatabaseLegacyTest::testDbRenameTable it was found that test MySql Schema::renameTable implementation is returning a value. The docs on the abstract class and the other drivers do not return values.

Proposed resolution

Remove the return statement from the MySql implementation.

Remaining tasks

User interface changes

none

API changes

none

Data model changes

none

Comments

mondrake created an issue. See original summary.

petiar’s picture

I can try to fix this, hopefully, it's not complicated.

petiar’s picture

StatusFileSize
new614 bytes

Patch included.

mondrake’s picture

Status: Active » Needs review
webapp's’s picture

Code change in above patch works fine.

mondrake’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thank you!

Let”s add a test to assert that no value is returned.

In the kernel test SchemaTest the method is called twice. It wuold be sufficient to wrap those calls in a asserNull.

Then let”s have here a test only patch and a combined test+fix patch.

petiar’s picture

Hi all,

I am not very familiar with the tests, but I guess you wanted something like this? Let me know if that helps.

Thanks.
Petiar.

mondrake’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Yes, let's run tests to see if they are ok. Thanks!

The last submitted patch, 7: removing-return-command-2996560-7-test.patch, failed testing. View results

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks great!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

As this is changing a return value for the most common DB I think we should have a change record. BC is hard here. It's perfectly reasonable for code to have done:

if ($schema->renameTable('my_table', 'my_better_named_table')) {
  // Make other changes.
}

even though this is not documented by the API someone somewhere will depend upon this behaviour - especially since this is a hangover from Drupal 7 (interestingly though not Drupal 6)

And we should only make the change in 8.7.x to give people time to adapt any code.

Needs work for the change record. The patch and tests look great.

andypost’s picture

Status: Needs work » Needs review

@alexpott Not sure that return value is changing - before it was returning NULL (in worst case \Drupal\Core\Database\Connection::handleQueryException() also returns NULL) so I do not see how it may affect already existing code - I found it just typo that return used for no reason. Also test in #7 shows that core at least always getting null return code

Otoh I see \Drupal\Core\Database\Connection::defaultOptions() defines 'return' => Database::RETURN_STATEMENT as result but it is always NULL at the end, so maybe there case when it could be not null... not sure - needs other pair of eyes on it

alexpott’s picture

@andypost doesn't the test in #7 prove that the return value has changed for MySQL - from a \Drupal\Core\Database\StatementInterface object to a NULL?

andypost’s picture

@alexpott the removing-return-command-2996560-7-test.patch shows that statement returned for mysql only - I guess because default options but not clear how it could be used for

andypost’s picture

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

I think with the CR this is now fine. The example code in #11 would have worked only for MySql, and failed with other drivers. Let's fix this inconsistency,

alexpott’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the CR.

Committed 716828d and pushed to 8.7.x. Thanks!

  • alexpott committed 716828d on 8.7.x
    Issue #2996560 by petiar, mondrake, andypost: MySql Schema::renameTable...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.