Make WordPress Core

Opened 4 years ago

Closed 7 months ago

Last modified 7 months ago

#40399 closed defect (bug) (fixed)

Post Status Inherited not Supported with REST API

Reported by: dfenton Owned by: TimothyBlynJacobs
Milestone: 5.6 Priority: normal
Severity: normal Version: 4.7.3
Component: REST API Keywords: has-patch has-unit-tests
Focuses: Cc:

Description (last modified by kadamwhite)

I'm trying to use the REST API to update a post_meta field on an an image of post_type="attachment", which is itself attached to an existing post of post_type="post" that is published and password protected.

Since the image is an attachment that is attached to another post, WordPress has set the post_status of the attachment to "inherit".

When I try to update the attachment from the REST API endpoint I'm getting the following error:

Uncaught Error: Syntax error, unrecognized expression: {"code":"rest_invalid_param","message":"Invalid parameter(s): status","data":{"status":400,"params":{"status":"status is not one of publish, future, draft, pending, private."}}}

It's clear in the documentation that post_status="inherit" isn't supported by the REST API for Media endpoints but I'm not sure if this is a bug or merely an oversight. My feeling is that since WordPress supports and sets attachments to "inherit" as a post_status, that the API should accept that, particularly when it's perfectly happy to deliver that status to me on a GET request.

Change History (9)

#1 @pputzer
2 years ago

Still valid as of 5.1-nightly. I just stumbled upon this while trying to reduce the maintenance load of a plugin by switching from AJAX to the REST API. A pity that the PostMeta models were removed from the API in the beta stage :(

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

22 months ago

#3 @TimothyBlynJacobs
22 months ago

  • Description modified (diff)

You should absolutely be able to PUT back the response from a GET request. Perhaps we need to add a custom validate_callback the same way we did for templates in #39996.

In the meantime, to work around this you should be able to omit the status field from your request and WordPress will ignore it.

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

21 months ago

#5 @kadamwhite
21 months ago

  • Description modified (diff)
  • Milestone changed from Awaiting Review to Future Release

You should absolutely be able to PUT back the response from a GET request.

Agreed; assigning to Future Release, if anybody's keen to own this one it'd be a good thing to sort out in the next couple releases.

#6 @TimothyBlynJacobs
7 months ago

  • Milestone changed from Future Release to 5.6

This ticket was mentioned in PR #653 on WordPress/wordpress-develop by TimothyBJacobs.

7 months ago

  • Keywords has-patch has-unit-tests added

#8 @TimothyBlynJacobs
7 months ago

  • Owner set to TimothyBlynJacobs
  • Resolution set to fixed
  • Status changed from new to closed

In 49302:

REST API: Don't validate status if it hasn't changed.

In particular, this allows for sending status=inherit to an attachment if it's current status is inherit. This status would be rejected because it is an "internal" post status which isn't exposed.

As a general rule, a developer should always be able to PUT back a GET response without error.

Props dfenton, pputzer, TimothyBlynJacobs.
Fixes #40399.

#9 @prbot
7 months ago

TimothyBJacobs commented on PR #653:

Fixed in e66f459435eb8ee2bad083a9e8703a5151fdc0b3.

Note: See TracTickets for help on using tickets.