#24800 closed defect (bug) (fixed)
DROP TABLE error 1051 (Unknown table)
Reported by: | soulseekah | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Unit Tests | Keywords: | has-patch |
Focuses: | Cc: |
Description
When dropping a table via $wpdb->query
the query is rewritten to its temporary counterpart DROP TEMPORARY TABLE
.
http://core.trac.wordpress.org/browser/tests/trunk/includes/testcase.php#L55
However, all CREATE TABLE
queries are not rewritten to CREATE TEMPORARY TABLE
, so when the time comes the database shoves an error into the face of anyone who's trying to drop a table.
This is currently only relevant to custom tests extending from the WP_UnitTestCase
class.
Attachments (4)
Change History (12)
#2
@
11 years ago
The create filter wasn't as careful as the drop filter, as it was working on only dbDelta creation queries, not any queries that go through $wpdb.
24800.2.diff (untested) makes both filters much more careful.
#3
@
11 years ago
Related tests seem to pass fine (unrelated current failing tests reside in XMLRPC, formats and media).
#4
follow-up:
↓ 5
@
11 years ago
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed
In 27041:
#5
in reply to:
↑ 4
@
11 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Replying to nacin:
In 27041:
This has broken some things. I noticed that some unit tests for one of my plugins were giving strange results. In one unit test for multisite, a blog would be created using $this->factory->blog->create()
. Then stuff would fly apart in the next unit test, because for some reason the changes were being committed instead of rolled-back by MySQL. I eventually traced this down to the fact that the CREATE TABLE
queries for new a new blog will have a leading newline. That is causing the CREATE TABLE
query not to be converted to a CREATE TEMPORARY TABLE
query. And a CREATE TABLE
query will automatically cause a commit. It worked before, because it was a simple str_replace()
. Now it will ignore the query if there is leading whitespace.
I'll attach a patch with a possible fix.
#6
@
11 years ago
- Keywords has-patch added
Also, note that the names of these functions were changed (the plural was dropped), so anybody who is hacking them (e.g., for testing plugin install/uninstall), will have to update.
Again, just to clarify: the issue is in the
WP_UnitTestCase
, which doesn't allow custom code toCREATE
andDROP
tables. This is relevant for custom plugin and theme tests making use of the provided WordPress test case class.