Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 3 years ago

#42600 closed defect (bug) (duplicate)

Adding term with duplicate name via REST API no longer returning existing term ID

Reported by: shooper's profile shooper Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9
Component: REST API Keywords: has-patch has-unit-tests dev-feedback
Focuses: rest-api Cc:

Description

Reported by @coleh in the ticket that caused this change, #41370.

In WordPress 4.9, if you add a term with a duplicate name using the REST API, the 'data' element used to contain the ID of the existing term. It now just an array that only includes the HTTP status code.

Here's the output of the REST API calls in both 4.8 and 4.9:

In WordPress 4.8, returns HTTP status code 500 and this body:

{
    "code": "term_exists",
    "message": "A term with the name provided already exists with this parent.",
    "data": 2
}

In WordPress 4.9, returns HTTP status code 409 and this body:

{
    "code": "term_exists",
    "message": "A term with the name provided already exists with this parent.",
    "data": {
        "status": 409
    }
}

Note that this was my original patch. I'm happy to provide the fix for it here.

Attachments (1)

42600.diff (1.8 KB) - added by shooper 7 years ago.
Patch that adds term_id to the response's data array.

Download all attachments as: .zip

Change History (4)

#1 @shooper
7 years ago

I don't believe it's possible to have 100% backward compatibility with 4.8.x as by changing the HTTP status code to 409, the data element in the response became an array instead of an integer. What I suggest is adding 'term_id' to the data array.

Is there a way to change the status code without using the add_data() function?

@shooper
7 years ago

Patch that adds term_id to the response's data array.

#2 @shooper
7 years ago

  • Keywords has-patch has-unit-tests dev-feedback added

Provided a patch that adds term_id to the REST API response. Are we OK with this approach, given that it still doesn't provide 100% backwards compatibility with the response given in WP 4.8.x ?

#3 @swissspidy
7 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #42597.

The existing term ID is added to the error object one line above, isn‘t it?

Would you mind adding your patch to the existing ticket for this bug? Thanks!

Note: See TracTickets for help on using tickets.