[wp-trac] [WordPress Trac] #57012: WP_Query caching discards `posts_fields` and `posts_clauses['fields']` filters.

WordPress Trac noreply at wordpress.org
Sat Nov 12 14:49:40 UTC 2022


#57012: WP_Query caching discards `posts_fields` and `posts_clauses['fields']`
filters.
-------------------------------------------------+-------------------------
 Reporter:  peterwilsoncc                        |       Owner:
                                                 |  peterwilsoncc
     Type:  defect (bug)                         |      Status:  reopened
 Priority:  normal                               |   Milestone:  6.1.1
Component:  Query                                |     Version:  6.1
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests commit      |     Focuses:
  fixed-major                                    |  performance
-------------------------------------------------+-------------------------

Comment (by SergeyBiryukov):

 In [changeset:"54829" 54829]:
 {{{
 #!CommitTicketReference repository="" revision="54829"
 Tests: Resolve `WP_Query` test failures on MariaDB due to indeterminate
 sort order.

 [54768] added a few tests to verify that caching within `WP_Query` is
 bypassed when the `SELECT` clause has been modified via a filter, to avoid
 cache key collisions and the returning of incomplete or unexpected
 results.

 However, creating several posts with the same date/time fields can result
 in inconsistent sort ordering between MySQL and MariaDB, as each engine
 refines the order further using a different index.

 This commit aims to stabilize the tests by using `assertEqualSets()`
 instead of `assertEquals()`, since testing the order is out of their
 scope. Includes removing `array_unshift()` and `array_reverse()` calls as
 no longer needed.

 This resolves a few test failures on MariaDB along the lines of:
 {{{
 Tests_Query_FieldsClause::test_should_limit_fields_to_id_and_parent_subset
 Posts property for first query is not of expected form.
 Failed asserting that two arrays are equal.
 --- Expected
 +++ Actual
 @@ @@
  Array (
      0 => stdClass Object (
 -        'ID' => 36019
 +        'ID' => 36015
          'post_parent' => 0
      )
      1 => stdClass Object (
 -        'ID' => 36018
 +        'ID' => 36016
          'post_parent' => 0
      )
      2 => stdClass Object (...)
      3 => stdClass Object (
 -        'ID' => 36016
 +        'ID' => 36018
          'post_parent' => 0
      )
      4 => stdClass Object (
 -        'ID' => 36015
 +        'ID' => 36019
          'post_parent' => 0
      )
  )

 /tmp/wp-test-runner/tests/phpunit/tests/query/fieldsClause.php:67
 /tmp/wp-test-runner/phpunit-5.7.phar:598
 }}}

 Follow-up to [54768].

 Props peterwilsoncc, SergeyBiryukov.
 See #57012.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57012#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list