[wp-trac] [WordPress Trac] #25775: WP_Date_Query table prefixing

WordPress Trac noreply at wordpress.org
Fri Nov 22 18:59:07 UTC 2013


#25775: WP_Date_Query table prefixing
----------------------------------------+------------------
 Reporter:  ew_holmes                   |       Owner:
     Type:  defect (bug)                |      Status:  new
 Priority:  normal                      |   Milestone:  3.8
Component:  Query                       |     Version:  3.7
 Severity:  major                       |  Resolution:
 Keywords:  has-patch needs-unit-tests  |
----------------------------------------+------------------

Comment (by wonderboymusic):

 So, I found some delightful bugs when running some of the Date Query unit
 tests directly.

 Things:
 * Some unit tests produce database errors, but when they run in certain
 contexts, database error suppression has been triggered in a previous test
 and not toggled back on
 * Date Query only affects the `WHERE` clause, but allows arguments that
 would otherwise produce a `JOIN` - there is currently no code enforcing
 that `JOIN`, so the queries can blow up
 * Prefixing raises errors for unknown tables, where previously it was only
 an unknown column error
 * If you don't pass a `column` arg when adding `date_query` to a query for
 comments, the default value is `post_date`, but there was no code even
 attempting to `JOIN`- I am not sure how some of these tests ever passed.

 What I Did in [attachment:25775.diff​ 25775.diff​]:
 * Made a unit test that makes `date_query`s with each of the valid columns
 and then asserts RegEx on the generated SQL
 * in `WP_Date_Query`, add 2 properties: `$join_comments` and
 `$joins_posts` which are toggled on when the column is being validated
 * In `WP_Query`, if `date_query` is an arg, check for `->joins_comments`
 after `->get_sql()`, and then way down the road, enforce the `JOIN` if the
 resulting `$join` var doesn't contain the table
 * In `WP_Comment_Query`, if `date_query` is an arg, check for
 `->joins_posts` after `->get_sql()`, and then way down the road, enforce
 the `JOIN` if the resulting `$join` var doesn't contain the table

--
Ticket URL: <http://core.trac.wordpress.org/ticket/25775#comment:9>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list