Opened 6 years ago
Closed 6 years ago
#45299 closed defect (bug) (fixed)
`wpdb->last_result` may not be countable
Reported by: | desrosj | Owned by: | |
---|---|---|---|
Milestone: | 5.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Database | Keywords: | php73 has-patch has-unit-tests fixed-5.0 |
Focuses: | Cc: |
Description
In wpdb->get_col()
, $wpdb->last_result
may be null
or an empty string, which are uncountable values.
This can be triggered by passing an empty query string as a query.
Props @spacedmonkey for pointing this out.
Attachments (4)
Change History (16)
#2
@
6 years ago
While reviewing this bug, I found a second place, where last_result being null
would be an issue.
See attached 45299-bug1.diff which is a simple fix. It might have to go in another ticket.
#3
@
6 years ago
- Component changed from Query to Database
- Keywords has-patch needs-testing added; needs-patch removed
A visual review of the diffs looks good, marking as has-patch, needs-testing
.
- 45299-bug1.diff matches the check used next block down for
ARRAY_*
. - 45299.diff
get_col()
differs from the rest of theget_*()
methods (which returnnull
in this case) and always returns an array, so this also seems like a sane change.
#5
@
6 years ago
45299.2.diff is a patch that combines the two changes and applies to the 5.0 branch.
Also, set up a test build on Travis. The changes are not causing any test failures, but I doubt there are tests that would trigger this specific edge case.
This ticket was mentioned in Slack in #core by spacedmonkey. View the logs.
6 years ago
#10
@
6 years ago
45299.3.diff applies cleanly to the 4.9 branch, if backporting is necessary (more details here).
For a bit more detail, this notice error is generated when an invalid or empty query is passed to the
get_col
. It is kind of edge case but not to replicate.The issue, is because
get_row
can return alast_result
as null.There are two fixes for this, either we change
get_row
, so it returns an empty array on failure. But this could be a breaking change as it changes functionality.I have patched a patch for a much similar solution, that doesn't even require is_countable to be called.