Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#38985 closed defect (bug) (fixed)

REST API: Some orderby parameters are broken

Reported by: jnylen0's profile jnylen0 Owned by: jnylen0's profile jnylen0
Milestone: 4.7 Priority: normal
Severity: normal Version:
Component: REST API Keywords: has-unit-tests has-patch commit dev-reviewed
Focuses: Cc:

Description

The orderby parameters id and slug are currently broken for posts. Since they don't map directly to WP_Query values, and there is no code to translate them, they don't do anything.

The include parameter works, but only if a list of IDs is specified via the include parameter. We should return an error for orderby=include without this parameter, like we do for orderby=relevance without search.

Attachments (3)

38985.diff (4.1 KB) - added by ChopinBach 10 years ago.
Adds an error when include orderby is specified without an include parameter. The id and slug orderby parameters now properly map to their correct fields ID and post_name. There may still be more problems surrounding orderby, but this addressed the ones reported in this ticket.
38985.2.diff (4.2 KB) - added by ChopinBach 10 years ago.
Adds an error when include orderby is specified without an include parameter. The id and slug orderby parameters now properly map to their correct fields ID and post_name. There may still be more problems surrounding orderby, but this addressed the ones reported in this ticket. This is a slightly cleaner approach, and makes future maintenance of the orderby params simpler.
38985.3.diff (4.4 KB) - added by jnylen0 10 years ago.
Reuse an existing error string; rename mappings to $orderby_mappings

Download all attachments as: .zip

Change History (17)

#1 @jnylen0
10 years ago

  • Component changed from General to REST API

This ticket was mentioned in Slack in #core-restapi by jnylen. View the logs.


10 years ago

#3 @ChopinBach
10 years ago

@jnylen0

If you aren't already prepping a patch I can do a patch for it. It should be a lot cleaner than my last attempt.

#4 @joehoyle
10 years ago

I guess we should remove id and slug given there's no simple way to achieve this with WP_Query.

#5 @jnylen0
10 years ago

I haven't started on a patch for this yet.

It looks like we can just map idID and slugname, like we already do for includepost__in. Presumably this is how it worked at one point.

I think this issue shows that we also need to add tests for the actual SQL - using the posts_orderby filter seems like a good way to achieve this. In fact if we have that in place then we could probably drop the testing of results lists altogether which can be a bit tricky.

I'm also wondering if there is similar breakage in the orderby parameters of other endpoints.

@ChopinBach
10 years ago

Adds an error when include orderby is specified without an include parameter. The id and slug orderby parameters now properly map to their correct fields ID and post_name. There may still be more problems surrounding orderby, but this addressed the ones reported in this ticket.

This ticket was mentioned in Slack in #core-restapi by chopinbach. View the logs.


10 years ago

#7 @ChopinBach
10 years ago

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed

@ChopinBach
10 years ago

Adds an error when include orderby is specified without an include parameter. The id and slug orderby parameters now properly map to their correct fields ID and post_name. There may still be more problems surrounding orderby, but this addressed the ones reported in this ticket. This is a slightly cleaner approach, and makes future maintenance of the orderby params simpler.

This ticket was mentioned in Slack in #core by helen. View the logs.


10 years ago

#9 @rachelbaker
10 years ago

  • Focuses performance added
  • Keywords needs-refresh added
  • Owner set to jnylen0
  • Status changed from new to assigned

We are in a string freeze for 4.7 and cannot introduce a new error message.

I see two options here:

  1. We ignore the include orderby value if the request does not include the related include parameter.
  2. We remove support for the 'orderby' => 'include' for 4.7.

I would like to do Option #1 if possible, but we are running out of time here folks.

#10 @rachelbaker
10 years ago

  • Focuses performance removed

@jnylen0
10 years ago

Reuse an existing error string; rename mappings to $orderby_mappings

#11 @jnylen0
10 years ago

  • Keywords needs-refresh removed

Option 3: reuse an existing error message for 4.7 and clean it up in 4.8.

Done in 38985.3.diff; also renamed $orderby_possibles$orderby_mappings to match $parameter_mappings in the same file.

#12 @pento
10 years ago

  • Keywords commit dev-feedback added

I'm cool with 38985.3.diff, there's nothing insane that will cause everything to explode.

#13 @rachelbaker
10 years ago

  • Keywords dev-reviewed added; dev-feedback removed

#14 @rachelbaker
10 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixed in [39440] and [39441] - referencing the wrong ticket number.

Note: See TracTickets for help on using tickets.